ChakraCommon.h 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. /// \mainpage Chakra Hosting API Reference
  6. ///
  7. /// Chakra is Microsoft's JavaScript engine. It is an integral part of Internet Explorer but can
  8. /// also be hosted independently by other applications. This reference describes the APIs available
  9. /// to applications to host Chakra.
  10. ///
  11. /// This file contains the common API set shared among all Chakra releases. For Windows-specific
  12. /// releases, see chakrart.h.
  13. /// \file
  14. /// \brief The base Chakra hosting API.
  15. ///
  16. /// This file contains a flat C API layer. This is the API exported by chakra.dll.
  17. #ifdef _MSC_VER
  18. #pragma once
  19. #endif // _MSC_VER
  20. #ifndef _CHAKRACOMMON_H_
  21. #define _CHAKRACOMMON_H_
  22. #include <oaidl.h>
  23. /// <summary>
  24. /// An error code returned from a Chakra hosting API.
  25. /// </summary>
  26. typedef _Return_type_success_(return == 0) enum _JsErrorCode : unsigned int
  27. {
  28. /// <summary>
  29. /// Success error code.
  30. /// </summary>
  31. JsNoError = 0,
  32. /// <summary>
  33. /// Category of errors that relates to incorrect usage of the API itself.
  34. /// </summary>
  35. JsErrorCategoryUsage = 0x10000,
  36. /// <summary>
  37. /// An argument to a hosting API was invalid.
  38. /// </summary>
  39. JsErrorInvalidArgument,
  40. /// <summary>
  41. /// An argument to a hosting API was null in a context where null is not allowed.
  42. /// </summary>
  43. JsErrorNullArgument,
  44. /// <summary>
  45. /// The hosting API requires that a context be current, but there is no current context.
  46. /// </summary>
  47. JsErrorNoCurrentContext,
  48. /// <summary>
  49. /// The engine is in an exception state and no APIs can be called until the exception is
  50. /// cleared.
  51. /// </summary>
  52. JsErrorInExceptionState,
  53. /// <summary>
  54. /// A hosting API is not yet implemented.
  55. /// </summary>
  56. JsErrorNotImplemented,
  57. /// <summary>
  58. /// A hosting API was called on the wrong thread.
  59. /// </summary>
  60. JsErrorWrongThread,
  61. /// <summary>
  62. /// A runtime that is still in use cannot be disposed.
  63. /// </summary>
  64. JsErrorRuntimeInUse,
  65. /// <summary>
  66. /// A bad serialized script was used, or the serialized script was serialized by a
  67. /// different version of the Chakra engine.
  68. /// </summary>
  69. JsErrorBadSerializedScript,
  70. /// <summary>
  71. /// The runtime is in a disabled state.
  72. /// </summary>
  73. JsErrorInDisabledState,
  74. /// <summary>
  75. /// Runtime does not support reliable script interruption.
  76. /// </summary>
  77. JsErrorCannotDisableExecution,
  78. /// <summary>
  79. /// A heap enumeration is currently underway in the script context.
  80. /// </summary>
  81. JsErrorHeapEnumInProgress,
  82. /// <summary>
  83. /// A hosting API that operates on object values was called with a non-object value.
  84. /// </summary>
  85. JsErrorArgumentNotObject,
  86. /// <summary>
  87. /// A script context is in the middle of a profile callback.
  88. /// </summary>
  89. JsErrorInProfileCallback,
  90. /// <summary>
  91. /// A thread service callback is currently underway.
  92. /// </summary>
  93. JsErrorInThreadServiceCallback,
  94. /// <summary>
  95. /// Scripts cannot be serialized in debug contexts.
  96. /// </summary>
  97. JsErrorCannotSerializeDebugScript,
  98. /// <summary>
  99. /// The context cannot be put into a debug state because it is already in a debug state.
  100. /// </summary>
  101. JsErrorAlreadyDebuggingContext,
  102. /// <summary>
  103. /// The context cannot start profiling because it is already profiling.
  104. /// </summary>
  105. JsErrorAlreadyProfilingContext,
  106. /// <summary>
  107. /// Idle notification given when the host did not enable idle processing.
  108. /// </summary>
  109. JsErrorIdleNotEnabled,
  110. /// <summary>
  111. /// The context did not accept the enqueue callback.
  112. /// </summary>
  113. JsCannotSetProjectionEnqueueCallback,
  114. /// <summary>
  115. /// Failed to start projection.
  116. /// </summary>
  117. JsErrorCannotStartProjection,
  118. /// <summary>
  119. /// The operation is not supported in an object before collect callback.
  120. /// </summary>
  121. JsErrorInObjectBeforeCollectCallback,
  122. /// <summary>
  123. /// Object cannot be unwrapped to IInspectable pointer.
  124. /// </summary>
  125. JsErrorObjectNotInspectable,
  126. /// <summary>
  127. /// A hosting API that operates on symbol property ids but was called with a non-symbol property id.
  128. /// The error code is returned by JsGetSymbolFromPropertyId if the function is called with non-symbol property id.
  129. /// </summary>
  130. JsErrorPropertyNotSymbol,
  131. /// <summary>
  132. /// A hosting API that operates on string property ids but was called with a non-string property id.
  133. /// The error code is returned by existing JsGetPropertyNamefromId if the function is called with non-string property id.
  134. /// </summary>
  135. JsErrorPropertyNotString,
  136. /// <summary>
  137. /// Category of errors that relates to errors occurring within the engine itself.
  138. /// </summary>
  139. JsErrorCategoryEngine = 0x20000,
  140. /// <summary>
  141. /// The Chakra engine has run out of memory.
  142. /// </summary>
  143. JsErrorOutOfMemory,
  144. /// <summary>
  145. /// Category of errors that relates to errors in a script.
  146. /// </summary>
  147. JsErrorCategoryScript = 0x30000,
  148. /// <summary>
  149. /// A JavaScript exception occurred while running a script.
  150. /// </summary>
  151. JsErrorScriptException,
  152. /// <summary>
  153. /// JavaScript failed to compile.
  154. /// </summary>
  155. JsErrorScriptCompile,
  156. /// <summary>
  157. /// A script was terminated due to a request to suspend a runtime.
  158. /// </summary>
  159. JsErrorScriptTerminated,
  160. /// <summary>
  161. /// A script was terminated because it tried to use <c>eval</c> or <c>function</c> and eval
  162. /// was disabled.
  163. /// </summary>
  164. JsErrorScriptEvalDisabled,
  165. /// <summary>
  166. /// Category of errors that are fatal and signify failure of the engine.
  167. /// </summary>
  168. JsErrorCategoryFatal = 0x40000,
  169. /// <summary>
  170. /// A fatal error in the engine has occurred.
  171. /// </summary>
  172. JsErrorFatal,
  173. /// <summary>
  174. /// A hosting API was called with object created on different javascript runtime.
  175. /// </summary>
  176. JsErrorWrongRuntime,
  177. } JsErrorCode;
  178. /// <summary>
  179. /// A handle to a Chakra runtime.
  180. /// </summary>
  181. /// <remarks>
  182. /// <para>
  183. /// Each Chakra runtime has its own independent execution engine, JIT compiler, and garbage
  184. /// collected heap. As such, each runtime is completely isolated from other runtimes.
  185. /// </para>
  186. /// <para>
  187. /// Runtimes can be used on any thread, but only one thread can call into a runtime at any
  188. /// time.
  189. /// </para>
  190. /// <para>
  191. /// NOTE: A <c>JsRuntimeHandle</c>, unlike other object references in the Chakra hosting API,
  192. /// is not garbage collected since it contains the garbage collected heap itself. A runtime
  193. /// will continue to exist until <c>JsDisposeRuntime</c> is called.
  194. /// </para>
  195. /// </remarks>
  196. typedef void *JsRuntimeHandle;
  197. /// <summary>
  198. /// An invalid runtime handle.
  199. /// </summary>
  200. const JsRuntimeHandle JS_INVALID_RUNTIME_HANDLE = NULL;
  201. /// <summary>
  202. /// A reference to an object owned by the Chakra garbage collector.
  203. /// </summary>
  204. /// <remarks>
  205. /// A Chakra runtime will automatically track <c>JsRef</c> references as long as they are
  206. /// stored in local variables or in parameters (i.e. on the stack). Storing a <c>JsRef</c>
  207. /// somewhere other than on the stack requires calling <c>JsAddRef</c> and <c>JsRelease</c> to
  208. /// manage the lifetime of the object, otherwise the garbage collector may free the object
  209. /// while it is still in use.
  210. /// </remarks>
  211. typedef void *JsRef;
  212. /// <summary>
  213. /// An invalid reference.
  214. /// </summary>
  215. const JsRef JS_INVALID_REFERENCE = NULL;
  216. /// <summary>
  217. /// A reference to a script context.
  218. /// </summary>
  219. /// <remarks>
  220. /// <para>
  221. /// Each script context contains its own global object, distinct from the global object in
  222. /// other script contexts.
  223. /// </para>
  224. /// <para>
  225. /// Many Chakra hosting APIs require an "active" script context, which can be set using
  226. /// <c>JsSetCurrentContext</c>. Chakra hosting APIs that require a current context to be set
  227. /// will note that explicitly in their documentation.
  228. /// </para>
  229. /// </remarks>
  230. typedef JsRef JsContextRef;
  231. /// <summary>
  232. /// A reference to a JavaScript value.
  233. /// </summary>
  234. /// <remarks>
  235. /// A JavaScript value is one of the following types of values: undefined, null, Boolean,
  236. /// string, number, or object.
  237. /// </remarks>
  238. typedef JsRef JsValueRef;
  239. /// <summary>
  240. /// A cookie that identifies a script for debugging purposes.
  241. /// </summary>
  242. typedef DWORD_PTR JsSourceContext;
  243. /// <summary>
  244. /// An empty source context.
  245. /// </summary>
  246. const JsSourceContext JS_SOURCE_CONTEXT_NONE = (JsSourceContext)-1;
  247. /// <summary>
  248. /// A property identifier.
  249. /// </summary>
  250. /// <remarks>
  251. /// Property identifiers are used to refer to properties of JavaScript objects instead of using
  252. /// strings.
  253. /// </remarks>
  254. typedef JsRef JsPropertyIdRef;
  255. /// <summary>
  256. /// Attributes of a runtime.
  257. /// </summary>
  258. typedef enum _JsRuntimeAttributes
  259. {
  260. /// <summary>
  261. /// No special attributes.
  262. /// </summary>
  263. JsRuntimeAttributeNone = 0x00000000,
  264. /// <summary>
  265. /// The runtime will not do any work (such as garbage collection) on background threads.
  266. /// </summary>
  267. JsRuntimeAttributeDisableBackgroundWork = 0x00000001,
  268. /// <summary>
  269. /// The runtime should support reliable script interruption. This increases the number of
  270. /// places where the runtime will check for a script interrupt request at the cost of a
  271. /// small amount of runtime performance.
  272. /// </summary>
  273. JsRuntimeAttributeAllowScriptInterrupt = 0x00000002,
  274. /// <summary>
  275. /// Host will call <c>JsIdle</c>, so enable idle processing. Otherwise, the runtime will
  276. /// manage memory slightly more aggressively.
  277. /// </summary>
  278. JsRuntimeAttributeEnableIdleProcessing = 0x00000004,
  279. /// <summary>
  280. /// Runtime will not generate native code.
  281. /// </summary>
  282. JsRuntimeAttributeDisableNativeCodeGeneration = 0x00000008,
  283. /// <summary>
  284. /// Using <c>eval</c> or <c>function</c> constructor will throw an exception.
  285. /// </summary>
  286. JsRuntimeAttributeDisableEval = 0x00000010,
  287. /// <summary>
  288. /// Runtime will enable all experimental features.
  289. /// </summary>
  290. JsRuntimeAttributeEnableExperimentalFeatures = 0x00000020,
  291. /// <summary>
  292. /// Calling <c>JsSetException</c> will also dispatch the exception to the script debugger
  293. /// (if any) giving the debugger a chance to break on the exception.
  294. /// </summary>
  295. JsRuntimeAttributeDispatchSetExceptionsToDebugger = 0x00000040
  296. } JsRuntimeAttributes;
  297. /// <summary>
  298. /// The type of a typed JavaScript array.
  299. /// </summary>
  300. typedef enum _JsTypedArrayType
  301. {
  302. /// <summary>
  303. /// An int8 array.
  304. /// </summary>
  305. JsArrayTypeInt8,
  306. /// <summary>
  307. /// An uint8 array.
  308. /// </summary>
  309. JsArrayTypeUint8,
  310. /// <summary>
  311. /// An uint8 clamped array.
  312. /// </summary>
  313. JsArrayTypeUint8Clamped,
  314. /// <summary>
  315. /// An int16 array.
  316. /// </summary>
  317. JsArrayTypeInt16,
  318. /// <summary>
  319. /// An uint16 array.
  320. /// </summary>
  321. JsArrayTypeUint16,
  322. /// <summary>
  323. /// An int32 array.
  324. /// </summary>
  325. JsArrayTypeInt32,
  326. /// <summary>
  327. /// An uint32 array.
  328. /// </summary>
  329. JsArrayTypeUint32,
  330. /// <summary>
  331. /// A float32 array.
  332. /// </summary>
  333. JsArrayTypeFloat32,
  334. /// <summary>
  335. /// A float64 array.
  336. /// </summary>
  337. JsArrayTypeFloat64
  338. } JsTypedArrayType;
  339. /// <summary>
  340. /// Allocation callback event type.
  341. /// </summary>
  342. typedef enum _JsMemoryEventType
  343. {
  344. /// <summary>
  345. /// Indicates a request for memory allocation.
  346. /// </summary>
  347. JsMemoryAllocate = 0,
  348. /// <summary>
  349. /// Indicates a memory freeing event.
  350. /// </summary>
  351. JsMemoryFree = 1,
  352. /// <summary>
  353. /// Indicates a failed allocation event.
  354. /// </summary>
  355. JsMemoryFailure = 2
  356. } JsMemoryEventType;
  357. /// <summary>
  358. /// Attribute mask for JsParseScriptWithAttributes
  359. /// </summary>
  360. typedef enum _JsParseScriptAttributes {
  361. /// <summary>
  362. /// Default attribute
  363. /// </summary>
  364. JsParseScriptAttributeNone = 0x0,
  365. /// <summary>
  366. /// Specified script is internal and non-user code. Hidden from debugger
  367. /// </summary>
  368. JsParseScriptAttributeLibraryCode = 0x1
  369. } JsParseScriptAttributes;
  370. /// <summary>
  371. /// User implemented callback routine for memory allocation events
  372. /// </summary>
  373. /// <remarks>
  374. /// Use <c>JsSetRuntimeMemoryAllocationCallback</c> to register this callback.
  375. /// </remarks>
  376. /// <param name="callbackState">
  377. /// The state passed to <c>JsSetRuntimeMemoryAllocationCallback</c>.
  378. /// </param>
  379. /// <param name="allocationEvent">The type of type allocation event.</param>
  380. /// <param name="allocationSize">The size of the allocation.</param>
  381. /// <returns>
  382. /// For the <c>JsMemoryAllocate</c> event, returning <c>true</c> allows the runtime to continue
  383. /// with the allocation. Returning false indicates the allocation request is rejected. The
  384. /// return value is ignored for other allocation events.
  385. /// </returns>
  386. typedef bool (CALLBACK * JsMemoryAllocationCallback)(_In_opt_ void *callbackState, _In_ JsMemoryEventType allocationEvent, _In_ size_t allocationSize);
  387. /// <summary>
  388. /// A callback called before collection.
  389. /// </summary>
  390. /// <remarks>
  391. /// Use <c>JsSetBeforeCollectCallback</c> to register this callback.
  392. /// </remarks>
  393. /// <param name="callbackState">The state passed to <c>JsSetBeforeCollectCallback</c>.</param>
  394. typedef void (CALLBACK *JsBeforeCollectCallback)(_In_opt_ void *callbackState);
  395. /// <summary>
  396. /// A callback called before collecting an object.
  397. /// </summary>
  398. /// <remarks>
  399. /// Use <c>JsSetObjectBeforeCollectCallback</c> to register this callback.
  400. /// </remarks>
  401. /// <param name="ref">The object to be collected.</param>
  402. /// <param name="callbackState">The state passed to <c>JsSetObjectBeforeCollectCallback</c>.</param>
  403. typedef void (CALLBACK *JsObjectBeforeCollectCallback)(_In_ JsRef ref, _In_opt_ void *callbackState);
  404. /// <summary>
  405. /// A background work item callback.
  406. /// </summary>
  407. /// <remarks>
  408. /// This is passed to the host's thread service (if provided) to allow the host to
  409. /// invoke the work item callback on the background thread of its choice.
  410. /// </remarks>
  411. /// <param name="callbackState">Data argument passed to the thread service.</param>
  412. typedef void (CALLBACK *JsBackgroundWorkItemCallback)(_In_opt_ void *callbackState);
  413. /// <summary>
  414. /// A thread service callback.
  415. /// </summary>
  416. /// <remarks>
  417. /// The host can specify a background thread service when calling <c>JsCreateRuntime</c>. If
  418. /// specified, then background work items will be passed to the host using this callback. The
  419. /// host is expected to either begin executing the background work item immediately and return
  420. /// true or return false and the runtime will handle the work item in-thread.
  421. /// </remarks>
  422. /// <param name="callback">The callback for the background work item.</param>
  423. /// <param name="callbackState">The data argument to be passed to the callback.</param>
  424. typedef bool (CALLBACK *JsThreadServiceCallback)(_In_ JsBackgroundWorkItemCallback callback, _In_opt_ void *callbackState);
  425. /// <summary>
  426. /// Creates a new runtime.
  427. /// </summary>
  428. /// <param name="attributes">The attributes of the runtime to be created.</param>
  429. /// <param name="threadService">The thread service for the runtime. Can be null.</param>
  430. /// <param name="runtime">The runtime created.</param>
  431. /// <remarks>In the edge-mode binary, chakra.dll, this function lacks the <c>runtimeVersion</c>
  432. /// parameter (compare to jsrt9.h).</remarks>
  433. /// <returns>
  434. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  435. /// </returns>
  436. STDAPI_(JsErrorCode)
  437. JsCreateRuntime(
  438. _In_ JsRuntimeAttributes attributes,
  439. _In_opt_ JsThreadServiceCallback threadService,
  440. _Out_ JsRuntimeHandle *runtime);
  441. /// <summary>
  442. /// Performs a full garbage collection.
  443. /// </summary>
  444. /// <param name="runtime">The runtime in which the garbage collection will be performed.</param>
  445. /// <returns>
  446. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  447. /// </returns>
  448. STDAPI_(JsErrorCode)
  449. JsCollectGarbage(
  450. _In_ JsRuntimeHandle runtime);
  451. /// <summary>
  452. /// Disposes a runtime.
  453. /// </summary>
  454. /// <remarks>
  455. /// Once a runtime has been disposed, all resources owned by it are invalid and cannot be used.
  456. /// If the runtime is active (i.e. it is set to be current on a particular thread), it cannot
  457. /// be disposed.
  458. /// </remarks>
  459. /// <param name="runtime">The runtime to dispose.</param>
  460. /// <returns>
  461. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  462. /// </returns>
  463. STDAPI_(JsErrorCode)
  464. JsDisposeRuntime(
  465. _In_ JsRuntimeHandle runtime);
  466. /// <summary>
  467. /// Gets the current memory usage for a runtime.
  468. /// </summary>
  469. /// <remarks>
  470. /// Memory usage can be always be retrieved, regardless of whether or not the runtime is active
  471. /// on another thread.
  472. /// </remarks>
  473. /// <param name="runtime">The runtime whose memory usage is to be retrieved.</param>
  474. /// <param name="memoryUsage">The runtime's current memory usage, in bytes.</param>
  475. /// <returns>
  476. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  477. /// </returns>
  478. STDAPI_(JsErrorCode)
  479. JsGetRuntimeMemoryUsage(
  480. _In_ JsRuntimeHandle runtime,
  481. _Out_ size_t *memoryUsage);
  482. /// <summary>
  483. /// Gets the current memory limit for a runtime.
  484. /// </summary>
  485. /// <remarks>
  486. /// The memory limit of a runtime can be always be retrieved, regardless of whether or not the
  487. /// runtime is active on another thread.
  488. /// </remarks>
  489. /// <param name="runtime">The runtime whose memory limit is to be retrieved.</param>
  490. /// <param name="memoryLimit">
  491. /// The runtime's current memory limit, in bytes, or -1 if no limit has been set.
  492. /// </param>
  493. /// <returns>
  494. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  495. /// </returns>
  496. STDAPI_(JsErrorCode)
  497. JsGetRuntimeMemoryLimit(
  498. _In_ JsRuntimeHandle runtime,
  499. _Out_ size_t *memoryLimit);
  500. /// <summary>
  501. /// Sets the current memory limit for a runtime.
  502. /// </summary>
  503. /// <remarks>
  504. /// <para>
  505. /// A memory limit will cause any operation which exceeds the limit to fail with an "out of
  506. /// memory" error. Setting a runtime's memory limit to -1 means that the runtime has no memory
  507. /// limit. New runtimes default to having no memory limit. If the new memory limit exceeds
  508. /// current usage, the call will succeed and any future allocations in this runtime will fail
  509. /// until the runtime's memory usage drops below the limit.
  510. /// </para>
  511. /// <para>
  512. /// A runtime's memory limit can be always be set, regardless of whether or not the runtime is
  513. /// active on another thread.
  514. /// </para>
  515. /// </remarks>
  516. /// <param name="runtime">The runtime whose memory limit is to be set.</param>
  517. /// <param name="memoryLimit">
  518. /// The new runtime memory limit, in bytes, or -1 for no memory limit.
  519. /// </param>
  520. /// <returns>
  521. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  522. /// </returns>
  523. STDAPI_(JsErrorCode)
  524. JsSetRuntimeMemoryLimit(
  525. _In_ JsRuntimeHandle runtime,
  526. _In_ size_t memoryLimit);
  527. /// <summary>
  528. /// Sets a memory allocation callback for specified runtime
  529. /// </summary>
  530. /// <remarks>
  531. /// <para>
  532. /// Registering a memory allocation callback will cause the runtime to call back to the host
  533. /// whenever it acquires memory from, or releases memory to, the OS. The callback routine is
  534. /// called before the runtime memory manager allocates a block of memory. The allocation will
  535. /// be rejected if the callback returns false. The runtime memory manager will also invoke the
  536. /// callback routine after freeing a block of memory, as well as after allocation failures.
  537. /// </para>
  538. /// <para>
  539. /// The callback is invoked on the current runtime execution thread, therefore execution is
  540. /// blocked until the callback completes.
  541. /// </para>
  542. /// <para>
  543. /// The return value of the callback is not stored; previously rejected allocations will not
  544. /// prevent the runtime from invoking the callback again later for new memory allocations.
  545. /// </para>
  546. /// </remarks>
  547. /// <param name="runtime">The runtime for which to register the allocation callback.</param>
  548. /// <param name="callbackState">
  549. /// User provided state that will be passed back to the callback.
  550. /// </param>
  551. /// <param name="allocationCallback">
  552. /// Memory allocation callback to be called for memory allocation events.
  553. /// </param>
  554. /// <returns>
  555. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  556. /// </returns>
  557. STDAPI_(JsErrorCode)
  558. JsSetRuntimeMemoryAllocationCallback(
  559. _In_ JsRuntimeHandle runtime,
  560. _In_opt_ void *callbackState,
  561. _In_ JsMemoryAllocationCallback allocationCallback);
  562. /// <summary>
  563. /// Sets a callback function that is called by the runtime before garbage collection.
  564. /// </summary>
  565. /// <remarks>
  566. /// <para>
  567. /// The callback is invoked on the current runtime execution thread, therefore execution is
  568. /// blocked until the callback completes.
  569. /// </para>
  570. /// <para>
  571. /// The callback can be used by hosts to prepare for garbage collection. For example, by
  572. /// releasing unnecessary references on Chakra objects.
  573. /// </para>
  574. /// </remarks>
  575. /// <param name="runtime">The runtime for which to register the allocation callback.</param>
  576. /// <param name="callbackState">
  577. /// User provided state that will be passed back to the callback.
  578. /// </param>
  579. /// <param name="beforeCollectCallback">The callback function being set.</param>
  580. /// <returns>
  581. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  582. /// </returns>
  583. STDAPI_(JsErrorCode)
  584. JsSetRuntimeBeforeCollectCallback(
  585. _In_ JsRuntimeHandle runtime,
  586. _In_opt_ void *callbackState,
  587. _In_ JsBeforeCollectCallback beforeCollectCallback);
  588. /// <summary>
  589. /// Adds a reference to a garbage collected object.
  590. /// </summary>
  591. /// <remarks>
  592. /// This only needs to be called on <c>JsRef</c> handles that are not going to be stored
  593. /// somewhere on the stack. Calling <c>JsAddRef</c> ensures that the object the <c>JsRef</c>
  594. /// refers to will not be freed until <c>JsRelease</c> is called.
  595. /// </remarks>
  596. /// <param name="ref">The object to add a reference to.</param>
  597. /// <param name="count">The object's new reference count (can pass in null).</param>
  598. /// <returns>
  599. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  600. /// </returns>
  601. STDAPI_(JsErrorCode)
  602. JsAddRef(
  603. _In_ JsRef ref,
  604. _Out_opt_ unsigned int *count);
  605. /// <summary>
  606. /// Releases a reference to a garbage collected object.
  607. /// </summary>
  608. /// <remarks>
  609. /// Removes a reference to a <c>JsRef</c> handle that was created by <c>JsAddRef</c>.
  610. /// </remarks>
  611. /// <param name="ref">The object to add a reference to.</param>
  612. /// <param name="count">The object's new reference count (can pass in null).</param>
  613. /// <returns>
  614. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  615. /// </returns>
  616. STDAPI_(JsErrorCode)
  617. JsRelease(
  618. _In_ JsRef ref,
  619. _Out_opt_ unsigned int *count);
  620. /// <summary>
  621. /// Sets a callback function that is called by the runtime before garbage collection of
  622. /// an object.
  623. /// </summary>
  624. /// <remarks>
  625. /// <para>
  626. /// The callback is invoked on the current runtime execution thread, therefore execution is
  627. /// blocked until the callback completes.
  628. /// </para>
  629. /// </remarks>
  630. /// <param name="ref">The object for which to register the callback.</param>
  631. /// <param name="callbackState">
  632. /// User provided state that will be passed back to the callback.
  633. /// </param>
  634. /// <param name="objectBeforeCollectCallback">The callback function being set. Use null to clear
  635. /// previously registered callback.</param>
  636. /// <returns>
  637. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  638. /// </returns>
  639. STDAPI_(JsErrorCode)
  640. JsSetObjectBeforeCollectCallback(
  641. _In_ JsRef ref,
  642. _In_opt_ void *callbackState,
  643. _In_ JsObjectBeforeCollectCallback objectBeforeCollectCallback);
  644. /// <summary>
  645. /// Creates a script context for running scripts.
  646. /// </summary>
  647. /// <remarks>
  648. /// Each script context has its own global object that is isolated from all other script
  649. /// contexts.
  650. /// </remarks>
  651. /// <param name="runtime">The runtime the script context is being created in.</param>
  652. /// <param name="newContext">The created script context.</param>
  653. /// <returns>
  654. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  655. /// </returns>
  656. STDAPI_(JsErrorCode)
  657. JsCreateContext(
  658. _In_ JsRuntimeHandle runtime,
  659. _Out_ JsContextRef *newContext);
  660. /// <summary>
  661. /// Gets the current script context on the thread.
  662. /// </summary>
  663. /// <param name="currentContext">
  664. /// The current script context on the thread, null if there is no current script context.
  665. /// </param>
  666. /// <returns>
  667. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  668. /// </returns>
  669. STDAPI_(JsErrorCode)
  670. JsGetCurrentContext(
  671. _Out_ JsContextRef *currentContext);
  672. /// <summary>
  673. /// Sets the current script context on the thread.
  674. /// </summary>
  675. /// <param name="context">The script context to make current.</param>
  676. /// <returns>
  677. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  678. /// </returns>
  679. STDAPI_(JsErrorCode)
  680. JsSetCurrentContext(
  681. _In_ JsContextRef context);
  682. /// <summary>
  683. /// Gets the script context that the object belongs to.
  684. /// </summary>
  685. /// <param name="object">The object to get the context from.</param>
  686. /// <param name="context">The context the object belongs to.</param>
  687. /// <returns>
  688. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  689. /// </returns>
  690. STDAPI_(JsErrorCode)
  691. JsGetContextOfObject(
  692. _In_ JsValueRef object,
  693. _Out_ JsContextRef *context);
  694. /// <summary>
  695. /// Gets the internal data set on JsrtContext.
  696. /// </summary>
  697. /// <param name="context">The context to get the data from.</param>
  698. /// <param name="data">The pointer to the data where data will be returned.</param>
  699. /// <returns>
  700. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  701. /// </returns>
  702. STDAPI_(JsErrorCode)
  703. JsGetContextData(
  704. _In_ JsContextRef context,
  705. _Out_ void **data);
  706. /// <summary>
  707. /// Sets the internal data of JsrtContext.
  708. /// </summary>
  709. /// <param name="context">The context to set the data to.</param>
  710. /// <param name="data">The pointer to the data to be set.</param>
  711. /// <returns>
  712. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  713. /// </returns>
  714. STDAPI_(JsErrorCode)
  715. JsSetContextData(
  716. _In_ JsContextRef context,
  717. _In_ void *data);
  718. /// <summary>
  719. /// Gets the runtime that the context belongs to.
  720. /// </summary>
  721. /// <param name="context">The context to get the runtime from.</param>
  722. /// <param name="runtime">The runtime the context belongs to.</param>
  723. /// <returns>
  724. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  725. /// </returns>
  726. STDAPI_(JsErrorCode)
  727. JsGetRuntime(
  728. _In_ JsContextRef context,
  729. _Out_ JsRuntimeHandle *runtime);
  730. /// <summary>
  731. /// Tells the runtime to do any idle processing it need to do.
  732. /// </summary>
  733. /// <remarks>
  734. /// <para>
  735. /// If idle processing has been enabled for the current runtime, calling <c>JsIdle</c> will
  736. /// inform the current runtime that the host is idle and that the runtime can perform
  737. /// memory cleanup tasks.
  738. /// </para>
  739. /// <para>
  740. /// <c>JsIdle</c> can also return the number of system ticks until there will be more idle work
  741. /// for the runtime to do. Calling <c>JsIdle</c> before this number of ticks has passed will do
  742. /// no work.
  743. /// </para>
  744. /// <para>
  745. /// Requires an active script context.
  746. /// </para>
  747. /// </remarks>
  748. /// <param name="nextIdleTick">
  749. /// The next system tick when there will be more idle work to do. Can be null. Returns the
  750. /// maximum number of ticks if there no upcoming idle work to do.
  751. /// </param>
  752. /// <returns>
  753. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  754. /// </returns>
  755. STDAPI_(JsErrorCode)
  756. JsIdle(
  757. _Out_opt_ unsigned int *nextIdleTick);
  758. /// <summary>
  759. /// Parses a script and returns a function representing the script.
  760. /// </summary>
  761. /// <remarks>
  762. /// Requires an active script context.
  763. /// </remarks>
  764. /// <param name="script">The script to parse.</param>
  765. /// <param name="sourceContext">
  766. /// A cookie identifying the script that can be used by debuggable script contexts.
  767. /// </param>
  768. /// <param name="sourceUrl">The location the script came from.</param>
  769. /// <param name="result">A function representing the script code.</param>
  770. /// <returns>
  771. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  772. /// </returns>
  773. STDAPI_(JsErrorCode)
  774. JsParseScript(
  775. _In_z_ const wchar_t *script,
  776. _In_ JsSourceContext sourceContext,
  777. _In_z_ const wchar_t *sourceUrl,
  778. _Out_ JsValueRef *result);
  779. /// <summary>
  780. /// Parses a script and returns a function representing the script.
  781. /// </summary>
  782. /// <remarks>
  783. /// Requires an active script context.
  784. /// </remarks>
  785. /// <param name="script">The script to parse.</param>
  786. /// <param name="sourceContext">
  787. /// A cookie identifying the script that can be used by debuggable script contexts.
  788. /// </param>
  789. /// <param name="sourceUrl">The location the script came from.</param>
  790. /// <param name="parseAttributes">Attribute mask for parsing the script</param>
  791. /// <param name="result">A function representing the script code.</param>
  792. /// <returns>
  793. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  794. /// </returns>
  795. STDAPI_(JsErrorCode)
  796. JsParseScriptWithAttributes(
  797. _In_z_ const wchar_t *script,
  798. _In_ JsSourceContext sourceContext,
  799. _In_z_ const wchar_t *sourceUrl,
  800. _In_ JsParseScriptAttributes parseAttributes,
  801. _Out_ JsValueRef *result);
  802. /// <summary>
  803. /// Executes a script.
  804. /// </summary>
  805. /// <remarks>
  806. /// Requires an active script context.
  807. /// </remarks>
  808. /// <param name="script">The script to run.</param>
  809. /// <param name="sourceContext">
  810. /// A cookie identifying the script that can be used by debuggable script contexts.
  811. /// </param>
  812. /// <param name="sourceUrl">The location the script came from.</param>
  813. /// <param name="result">The result of the script, if any. This parameter can be null.</param>
  814. /// <returns>
  815. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  816. /// </returns>
  817. STDAPI_(JsErrorCode)
  818. JsRunScript(
  819. _In_z_ const wchar_t *script,
  820. _In_ JsSourceContext sourceContext,
  821. _In_z_ const wchar_t *sourceUrl,
  822. _Out_ JsValueRef *result);
  823. /// <summary>
  824. /// Executes a module.
  825. /// </summary>
  826. /// <remarks>
  827. /// Requires an active script context.
  828. /// </remarks>
  829. /// <param name="script">The module script to parse and execute.</param>
  830. /// <param name="sourceContext">
  831. /// A cookie identifying the script that can be used by debuggable script contexts.
  832. /// </param>
  833. /// <param name="sourceUrl">The location the module script came from.</param>
  834. /// <param name="result">The result of executing the module script, if any. This parameter can be null.</param>
  835. /// <returns>
  836. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  837. /// </returns>
  838. STDAPI_(JsErrorCode)
  839. JsExperimentalApiRunModule(
  840. _In_z_ const wchar_t *script,
  841. _In_ JsSourceContext sourceContext,
  842. _In_z_ const wchar_t *sourceUrl,
  843. _Out_ JsValueRef *result);
  844. /// <summary>
  845. /// Serializes a parsed script to a buffer than can be reused.
  846. /// </summary>
  847. /// <remarks>
  848. /// <para>
  849. /// <c>JsSerializeScript</c> parses a script and then stores the parsed form of the script in a
  850. /// runtime-independent format. The serialized script then can be deserialized in any
  851. /// runtime without requiring the script to be re-parsed.
  852. /// </para>
  853. /// <para>
  854. /// Requires an active script context.
  855. /// </para>
  856. /// </remarks>
  857. /// <param name="script">The script to serialize.</param>
  858. /// <param name="buffer">The buffer to put the serialized script into. Can be null.</param>
  859. /// <param name="bufferSize">
  860. /// On entry, the size of the buffer, in bytes; on exit, the size of the buffer, in bytes,
  861. /// required to hold the serialized script.
  862. /// </param>
  863. /// <returns>
  864. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  865. /// </returns>
  866. STDAPI_(JsErrorCode)
  867. JsSerializeScript(
  868. _In_z_ const wchar_t *script,
  869. _Out_writes_to_opt_(*bufferSize, *bufferSize) BYTE *buffer,
  870. _Inout_ unsigned long *bufferSize);
  871. /// <summary>
  872. /// Called by the runtime to load the source code of the serialized script.
  873. /// The caller must keep the script buffer valid until the JsSerializedScriptUnloadCallback.
  874. /// </summary>
  875. /// <param name="sourceContext">The context passed to Js[Parse|Run]SerializedScriptWithCallback</param>
  876. /// <param name="scriptBuffer">The script returned.</param>
  877. /// <returns>
  878. /// true if the operation succeeded, false otherwise.
  879. /// </returns>
  880. typedef bool (CALLBACK * JsSerializedScriptLoadSourceCallback)(_In_ JsSourceContext sourceContext, _Outptr_result_z_ const wchar_t** scriptBuffer);
  881. /// <summary>
  882. /// Called by the runtime when it is finished with all resources related to the script execution.
  883. /// The caller should free the source if loaded, the byte code, and the context at this time.
  884. /// </summary>
  885. /// <param name="sourceContext">The context passed to Js[Parse|Run]SerializedScriptWithCallback</param>
  886. typedef void (CALLBACK * JsSerializedScriptUnloadCallback)(_In_ JsSourceContext sourceContext);
  887. /// <summary>
  888. /// Parses a serialized script and returns a function representing the script.
  889. /// Provides the ability to lazy load the script source only if/when it is needed.
  890. /// </summary>
  891. /// <remarks>
  892. /// <para>
  893. /// Requires an active script context.
  894. /// </para>
  895. /// <para>
  896. /// The runtime will hold on to the buffer until all instances of any functions created from
  897. /// the buffer are garbage collected. It will then call scriptUnloadCallback to inform the
  898. /// caller it is safe to release.
  899. /// </para>
  900. /// </remarks>
  901. /// <param name="scriptLoadCallback">Callback called when the source code of the script needs to be loaded.</param>
  902. /// <param name="scriptUnloadCallback">Callback called when the serialized script and source code are no longer needed.</param>
  903. /// <param name="buffer">The serialized script.</param>
  904. /// <param name="sourceContext">
  905. /// A cookie identifying the script that can be used by debuggable script contexts.
  906. /// This context will passed into scriptLoadCallback and scriptUnloadCallback.
  907. /// </param>
  908. /// <param name="sourceUrl">The location the script came from.</param>
  909. /// <param name="result">A function representing the script code.</param>
  910. /// <returns>
  911. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  912. /// </returns>
  913. STDAPI_(JsErrorCode)
  914. JsParseSerializedScriptWithCallback(
  915. _In_ JsSerializedScriptLoadSourceCallback scriptLoadCallback,
  916. _In_ JsSerializedScriptUnloadCallback scriptUnloadCallback,
  917. _In_ BYTE *buffer,
  918. _In_ JsSourceContext sourceContext,
  919. _In_z_ const wchar_t *sourceUrl,
  920. _Out_ JsValueRef * result);
  921. /// <summary>
  922. /// Runs a serialized script.
  923. /// Provides the ability to lazy load the script source only if/when it is needed.
  924. /// </summary>
  925. /// <remarks>
  926. /// <para>
  927. /// Requires an active script context.
  928. /// </para>
  929. /// <para>
  930. /// The runtime will hold on to the buffer until all instances of any functions created from
  931. /// the buffer are garbage collected. It will then call scriptUnloadCallback to inform the
  932. /// caller it is safe to release.
  933. /// </para>
  934. /// </remarks>
  935. /// <param name="scriptLoadCallback">Callback called when the source code of the script needs to be loaded.</param>
  936. /// <param name="scriptUnloadCallback">Callback called when the serialized script and source code are no longer needed.</param>
  937. /// <param name="buffer">The serialized script.</param>
  938. /// <param name="sourceContext">
  939. /// A cookie identifying the script that can be used by debuggable script contexts.
  940. /// This context will passed into scriptLoadCallback and scriptUnloadCallback.
  941. /// </param>
  942. /// <param name="sourceUrl">The location the script came from.</param>
  943. /// <param name="result">
  944. /// The result of running the script, if any. This parameter can be null.
  945. /// </param>
  946. /// <returns>
  947. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  948. /// </returns>
  949. STDAPI_(JsErrorCode)
  950. JsRunSerializedScriptWithCallback(
  951. _In_ JsSerializedScriptLoadSourceCallback scriptLoadCallback,
  952. _In_ JsSerializedScriptUnloadCallback scriptUnloadCallback,
  953. _In_ BYTE *buffer,
  954. _In_ JsSourceContext sourceContext,
  955. _In_z_ const wchar_t *sourceUrl,
  956. _Out_opt_ JsValueRef * result);
  957. /// <summary>
  958. /// Parses a serialized script and returns a function representing the script.
  959. /// </summary>
  960. /// <remarks>
  961. /// <para>
  962. /// Requires an active script context.
  963. /// </para>
  964. /// <para>
  965. /// The runtime will hold on to the buffer until all instances of any functions created from
  966. /// the buffer are garbage collected.
  967. /// </para>
  968. /// </remarks>
  969. /// <param name="script">The script to parse.</param>
  970. /// <param name="buffer">The serialized script.</param>
  971. /// <param name="sourceContext">
  972. /// A cookie identifying the script that can be used by debuggable script contexts.
  973. /// </param>
  974. /// <param name="sourceUrl">The location the script came from.</param>
  975. /// <param name="result">A function representing the script code.</param>
  976. /// <returns>
  977. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  978. /// </returns>
  979. STDAPI_(JsErrorCode)
  980. JsParseSerializedScript(
  981. _In_z_ const wchar_t *script,
  982. _In_ BYTE *buffer,
  983. _In_ JsSourceContext sourceContext,
  984. _In_z_ const wchar_t *sourceUrl,
  985. _Out_ JsValueRef *result);
  986. /// <summary>
  987. /// Runs a serialized script.
  988. /// </summary>
  989. /// <remarks>
  990. /// <para>
  991. /// Requires an active script context.
  992. /// </para>
  993. /// <para>
  994. /// The runtime will hold on to the buffer until all instances of any functions created from
  995. /// the buffer are garbage collected.
  996. /// </para>
  997. /// </remarks>
  998. /// <param name="script">The source code of the serialized script.</param>
  999. /// <param name="buffer">The serialized script.</param>
  1000. /// <param name="sourceContext">
  1001. /// A cookie identifying the script that can be used by debuggable script contexts.
  1002. /// </param>
  1003. /// <param name="sourceUrl">The location the script came from.</param>
  1004. /// <param name="result">
  1005. /// The result of running the script, if any. This parameter can be null.
  1006. /// </param>
  1007. /// <returns>
  1008. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1009. /// </returns>
  1010. STDAPI_(JsErrorCode)
  1011. JsRunSerializedScript(
  1012. _In_z_ const wchar_t *script,
  1013. _In_ BYTE *buffer,
  1014. _In_ JsSourceContext sourceContext,
  1015. _In_z_ const wchar_t *sourceUrl,
  1016. _Out_ JsValueRef *result);
  1017. /// <summary>
  1018. /// Gets the property ID associated with the name.
  1019. /// </summary>
  1020. /// <remarks>
  1021. /// <para>
  1022. /// Property IDs are specific to a context and cannot be used across contexts.
  1023. /// </para>
  1024. /// <para>
  1025. /// Requires an active script context.
  1026. /// </para>
  1027. /// </remarks>
  1028. /// <param name="name">
  1029. /// The name of the property ID to get or create. The name may consist of only digits.
  1030. /// </param>
  1031. /// <param name="propertyId">The property ID in this runtime for the given name.</param>
  1032. /// <returns>
  1033. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1034. /// </returns>
  1035. STDAPI_(JsErrorCode)
  1036. JsGetPropertyIdFromName(
  1037. _In_z_ const wchar_t *name,
  1038. _Out_ JsPropertyIdRef *propertyId);
  1039. /// <summary>
  1040. /// Gets the name associated with the property ID.
  1041. /// </summary>
  1042. /// <remarks>
  1043. /// <para>
  1044. /// Requires an active script context.
  1045. /// </para>
  1046. /// <para>
  1047. /// The returned buffer is valid as long as the runtime is alive and cannot be used
  1048. /// once the runtime has been disposed.
  1049. /// </para>
  1050. /// </remarks>
  1051. /// <param name="propertyId">The property ID to get the name of.</param>
  1052. /// <param name="name">The name associated with the property ID.</param>
  1053. /// <returns>
  1054. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1055. /// </returns>
  1056. STDAPI_(JsErrorCode)
  1057. JsGetPropertyNameFromId(
  1058. _In_ JsPropertyIdRef propertyId,
  1059. _Outptr_result_z_ const wchar_t **name);
  1060. /// <summary>
  1061. /// Gets the symbol associated with the property ID.
  1062. /// </summary>
  1063. /// <remarks>
  1064. /// <para>
  1065. /// Requires an active script context.
  1066. /// </para>
  1067. /// </remarks>
  1068. /// <param name="propertyId">The property ID to get the symbol of.</param>
  1069. /// <param name="symbol">The symbol associated with the property ID.</param>
  1070. /// <returns>
  1071. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1072. /// </returns>
  1073. STDAPI_(JsErrorCode)
  1074. JsGetSymbolFromPropertyId(
  1075. _In_ JsPropertyIdRef propertyId,
  1076. _Out_ JsValueRef *symbol);
  1077. /// <summary>
  1078. /// Type enumeration of a JavaScript property
  1079. /// </summary>
  1080. typedef enum _JsPropertyIdType {
  1081. /// <summary>
  1082. /// Type enumeration of a JavaScript string property
  1083. /// </summary>
  1084. JsPropertyIdTypeString,
  1085. /// <summary>
  1086. /// Type enumeration of a JavaScript symbol property
  1087. /// </summary>
  1088. JsPropertyIdTypeSymbol
  1089. } JsPropertyIdType;
  1090. /// <summary>
  1091. /// Gets the type of property
  1092. /// </summary>
  1093. /// <remarks>
  1094. /// <para>
  1095. /// Requires an active script context.
  1096. /// </para>
  1097. /// </remarks>
  1098. /// <param name="propertyId">The property ID to get the type of.</param>
  1099. /// <param name="propertyIdType">The JsPropertyIdType of the given property ID</param>
  1100. /// <returns>
  1101. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1102. /// </returns>
  1103. STDAPI_(JsErrorCode)
  1104. JsGetPropertyIdType(
  1105. _In_ JsPropertyIdRef propertyId,
  1106. _Out_ JsPropertyIdType* propertyIdType);
  1107. /// <summary>
  1108. /// Gets the property ID associated with the symbol.
  1109. /// </summary>
  1110. /// <remarks>
  1111. /// <para>
  1112. /// Property IDs are specific to a context and cannot be used across contexts.
  1113. /// </para>
  1114. /// <para>
  1115. /// Requires an active script context.
  1116. /// </para>
  1117. /// </remarks>
  1118. /// <param name="symbol">
  1119. /// The symbol whose property ID is being retrieved.
  1120. /// </param>
  1121. /// <param name="propertyId">The property ID for the given symbol.</param>
  1122. /// <returns>
  1123. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1124. /// </returns>
  1125. STDAPI_(JsErrorCode)
  1126. JsGetPropertyIdFromSymbol(
  1127. _In_ JsValueRef symbol,
  1128. _Out_ JsPropertyIdRef *propertyId);
  1129. /// <summary>
  1130. /// Creates a Javascript symbol.
  1131. /// </summary>
  1132. /// <remarks>
  1133. /// Requires an active script context.
  1134. /// </remarks>
  1135. /// <param name="description">The string description of the symbol. Can be null.</param>
  1136. /// <param name="result">The new symbol.</param>
  1137. /// <returns>
  1138. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1139. /// </returns>
  1140. STDAPI_(JsErrorCode)
  1141. JsCreateSymbol(
  1142. _In_ JsValueRef description,
  1143. _Out_ JsValueRef *result);
  1144. /// <summary>
  1145. /// Gets the list of all symbol properties on the object.
  1146. /// </summary>
  1147. /// <remarks>
  1148. /// Requires an active script context.
  1149. /// </remarks>
  1150. /// <param name="object">The object from which to get the property symbols.</param>
  1151. /// <param name="propertySymbols">An array of property symbols.</param>
  1152. /// <returns>
  1153. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1154. /// </returns>
  1155. STDAPI_(JsErrorCode)
  1156. JsGetOwnPropertySymbols(
  1157. _In_ JsValueRef object,
  1158. _Out_ JsValueRef *propertySymbols);
  1159. /// <summary>
  1160. /// Gets the value of <c>undefined</c> in the current script context.
  1161. /// </summary>
  1162. /// <remarks>
  1163. /// Requires an active script context.
  1164. /// </remarks>
  1165. /// <param name="undefinedValue">The <c>undefined</c> value.</param>
  1166. /// <returns>
  1167. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1168. /// </returns>
  1169. STDAPI_(JsErrorCode)
  1170. JsGetUndefinedValue(
  1171. _Out_ JsValueRef *undefinedValue);
  1172. /// <summary>
  1173. /// Gets the value of <c>null</c> in the current script context.
  1174. /// </summary>
  1175. /// <remarks>
  1176. /// Requires an active script context.
  1177. /// </remarks>
  1178. /// <param name="nullValue">The <c>null</c> value.</param>
  1179. /// <returns>
  1180. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1181. /// </returns>
  1182. STDAPI_(JsErrorCode)
  1183. JsGetNullValue(
  1184. _Out_ JsValueRef *nullValue);
  1185. /// <summary>
  1186. /// Gets the value of <c>true</c> in the current script context.
  1187. /// </summary>
  1188. /// <remarks>
  1189. /// Requires an active script context.
  1190. /// </remarks>
  1191. /// <param name="trueValue">The <c>true</c> value.</param>
  1192. /// <returns>
  1193. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1194. /// </returns>
  1195. STDAPI_(JsErrorCode)
  1196. JsGetTrueValue(
  1197. _Out_ JsValueRef *trueValue);
  1198. /// <summary>
  1199. /// Gets the value of <c>false</c> in the current script context.
  1200. /// </summary>
  1201. /// <remarks>
  1202. /// Requires an active script context.
  1203. /// </remarks>
  1204. /// <param name="falseValue">The <c>false</c> value.</param>
  1205. /// <returns>
  1206. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1207. /// </returns>
  1208. STDAPI_(JsErrorCode)
  1209. JsGetFalseValue(
  1210. _Out_ JsValueRef *falseValue);
  1211. /// <summary>
  1212. /// Creates a Boolean value from a <c>bool</c> value.
  1213. /// </summary>
  1214. /// <remarks>
  1215. /// Requires an active script context.
  1216. /// </remarks>
  1217. /// <param name="value">The value to be converted.</param>
  1218. /// <param name="booleanValue">The converted value.</param>
  1219. /// <returns>
  1220. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1221. /// </returns>
  1222. STDAPI_(JsErrorCode)
  1223. JsBoolToBoolean(
  1224. _In_ bool value,
  1225. _Out_ JsValueRef *booleanValue);
  1226. /// <summary>
  1227. /// Retrieves the <c>bool</c> value of a Boolean value.
  1228. /// </summary>
  1229. /// <param name="value">The value to be converted.</param>
  1230. /// <param name="boolValue">The converted value.</param>
  1231. /// <returns>
  1232. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1233. /// </returns>
  1234. STDAPI_(JsErrorCode)
  1235. JsBooleanToBool(
  1236. _In_ JsValueRef value,
  1237. _Out_ bool *boolValue);
  1238. /// <summary>
  1239. /// Converts the value to Boolean using standard JavaScript semantics.
  1240. /// </summary>
  1241. /// <remarks>
  1242. /// Requires an active script context.
  1243. /// </remarks>
  1244. /// <param name="value">The value to be converted.</param>
  1245. /// <param name="booleanValue">The converted value.</param>
  1246. /// <returns>
  1247. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1248. /// </returns>
  1249. STDAPI_(JsErrorCode)
  1250. JsConvertValueToBoolean(
  1251. _In_ JsValueRef value,
  1252. _Out_ JsValueRef *booleanValue);
  1253. /// <summary>
  1254. /// The JavaScript type of a JsValueRef.
  1255. /// </summary>
  1256. typedef enum _JsValueType
  1257. {
  1258. /// <summary>
  1259. /// The value is the <c>undefined</c> value.
  1260. /// </summary>
  1261. JsUndefined = 0,
  1262. /// <summary>
  1263. /// The value is the <c>null</c> value.
  1264. /// </summary>
  1265. JsNull = 1,
  1266. /// <summary>
  1267. /// The value is a JavaScript number value.
  1268. /// </summary>
  1269. JsNumber = 2,
  1270. /// <summary>
  1271. /// The value is a JavaScript string value.
  1272. /// </summary>
  1273. JsString = 3,
  1274. /// <summary>
  1275. /// The value is a JavaScript Boolean value.
  1276. /// </summary>
  1277. JsBoolean = 4,
  1278. /// <summary>
  1279. /// The value is a JavaScript object value.
  1280. /// </summary>
  1281. JsObject = 5,
  1282. /// <summary>
  1283. /// The value is a JavaScript function object value.
  1284. /// </summary>
  1285. JsFunction = 6,
  1286. /// <summary>
  1287. /// The value is a JavaScript error object value.
  1288. /// </summary>
  1289. JsError = 7,
  1290. /// <summary>
  1291. /// The value is a JavaScript array object value.
  1292. /// </summary>
  1293. JsArray = 8,
  1294. /// <summary>
  1295. /// The value is a JavaScript symbol value.
  1296. /// </summary>
  1297. JsSymbol = 9,
  1298. /// <summary>
  1299. /// The value is a JavaScript ArrayBuffer object value.
  1300. /// </summary>
  1301. JsArrayBuffer = 10,
  1302. /// <summary>
  1303. /// The value is a JavaScript typed array object value.
  1304. /// </summary>
  1305. JsTypedArray = 11,
  1306. /// <summary>
  1307. /// The value is a JavaScript DataView object value.
  1308. /// </summary>
  1309. JsDataView = 12,
  1310. } JsValueType;
  1311. /// <summary>
  1312. /// Gets the JavaScript type of a JsValueRef.
  1313. /// </summary>
  1314. /// <param name="value">The value whose type is to be returned.</param>
  1315. /// <param name="type">The type of the value.</param>
  1316. /// <returns>
  1317. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1318. /// </returns>
  1319. STDAPI_(JsErrorCode)
  1320. JsGetValueType(
  1321. _In_ JsValueRef value,
  1322. _Out_ JsValueType *type);
  1323. /// <summary>
  1324. /// Creates a number value from a <c>double</c> value.
  1325. /// </summary>
  1326. /// <remarks>
  1327. /// Requires an active script context.
  1328. /// </remarks>
  1329. /// <param name="doubleValue">The <c>double</c> to convert to a number value.</param>
  1330. /// <param name="value">The new number value.</param>
  1331. /// <returns>
  1332. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1333. /// </returns>
  1334. STDAPI_(JsErrorCode)
  1335. JsDoubleToNumber(
  1336. _In_ double doubleValue,
  1337. _Out_ JsValueRef *value);
  1338. /// <summary>
  1339. /// Creates a number value from an <c>int</c> value.
  1340. /// </summary>
  1341. /// <remarks>
  1342. /// Requires an active script context.
  1343. /// </remarks>
  1344. /// <param name="intValue">The <c>int</c> to convert to a number value.</param>
  1345. /// <param name="value">The new number value.</param>
  1346. /// <returns>
  1347. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1348. /// </returns>
  1349. STDAPI_(JsErrorCode)
  1350. JsIntToNumber(
  1351. _In_ int intValue,
  1352. _Out_ JsValueRef *value);
  1353. /// <summary>
  1354. /// Retrieves the <c>double</c> value of a number value.
  1355. /// </summary>
  1356. /// <remarks>
  1357. /// This function retrieves the value of a number value. It will fail with
  1358. /// <c>JsErrorInvalidArgument</c> if the type of the value is not number.
  1359. /// </remarks>
  1360. /// <param name="value">The number value to convert to a <c>double</c> value.</param>
  1361. /// <param name="doubleValue">The <c>double</c> value.</param>
  1362. /// <returns>
  1363. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1364. /// </returns>
  1365. STDAPI_(JsErrorCode)
  1366. JsNumberToDouble(
  1367. _In_ JsValueRef value,
  1368. _Out_ double *doubleValue);
  1369. /// <summary>
  1370. /// Retrieves the <c>int</c> value of a number value.
  1371. /// </summary>
  1372. /// <remarks>
  1373. /// This function retrieves the value of a number value and converts to an <c>int</c> value.
  1374. /// It will fail with <c>JsErrorInvalidArgument</c> if the type of the value is not number.
  1375. /// </remarks>
  1376. /// <param name="value">The number value to convert to an <c>int</c> value.</param>
  1377. /// <param name="intValue">The <c>int</c> value.</param>
  1378. /// <returns>
  1379. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1380. /// </returns>
  1381. STDAPI_(JsErrorCode)
  1382. JsNumberToInt(
  1383. _In_ JsValueRef value,
  1384. _Out_ int *intValue);
  1385. /// <summary>
  1386. /// Converts the value to number using standard JavaScript semantics.
  1387. /// </summary>
  1388. /// <remarks>
  1389. /// Requires an active script context.
  1390. /// </remarks>
  1391. /// <param name="value">The value to be converted.</param>
  1392. /// <param name="numberValue">The converted value.</param>
  1393. /// <returns>
  1394. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1395. /// </returns>
  1396. STDAPI_(JsErrorCode)
  1397. JsConvertValueToNumber(
  1398. _In_ JsValueRef value,
  1399. _Out_ JsValueRef *numberValue);
  1400. /// <summary>
  1401. /// Gets the length of a string value.
  1402. /// </summary>
  1403. /// <param name="stringValue">The string value to get the length of.</param>
  1404. /// <param name="length">The length of the string.</param>
  1405. /// <returns>
  1406. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1407. /// </returns>
  1408. STDAPI_(JsErrorCode)
  1409. JsGetStringLength(
  1410. _In_ JsValueRef stringValue,
  1411. _Out_ int *length);
  1412. /// <summary>
  1413. /// Creates a string value from a string pointer.
  1414. /// </summary>
  1415. /// <remarks>
  1416. /// Requires an active script context.
  1417. /// </remarks>
  1418. /// <param name="stringValue">The string pointer to convert to a string value.</param>
  1419. /// <param name="stringLength">The length of the string to convert.</param>
  1420. /// <param name="value">The new string value.</param>
  1421. /// <returns>
  1422. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1423. /// </returns>
  1424. STDAPI_(JsErrorCode)
  1425. JsPointerToString(
  1426. _In_reads_(stringLength) const wchar_t *stringValue,
  1427. _In_ size_t stringLength,
  1428. _Out_ JsValueRef *value);
  1429. /// <summary>
  1430. /// Retrieves the string pointer of a string value.
  1431. /// </summary>
  1432. /// <remarks>
  1433. /// <para>
  1434. /// This function retrieves the string pointer of a string value. It will fail with
  1435. /// <c>JsErrorInvalidArgument</c> if the type of the value is not string. The lifetime
  1436. /// of the string returned will be the same as the lifetime of the value it came from, however
  1437. /// the string pointer is not considered a reference to the value (and so will not keep it
  1438. /// from being collected).
  1439. /// </para>
  1440. /// <para>
  1441. /// Requires an active script context.
  1442. /// </para>
  1443. /// </remarks>
  1444. /// <param name="value">The string value to convert to a string pointer.</param>
  1445. /// <param name="stringValue">The string pointer.</param>
  1446. /// <param name="stringLength">The length of the string.</param>
  1447. /// <returns>
  1448. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1449. /// </returns>
  1450. STDAPI_(JsErrorCode)
  1451. JsStringToPointer(
  1452. _In_ JsValueRef value,
  1453. _Outptr_result_buffer_(*stringLength) const wchar_t **stringValue,
  1454. _Out_ size_t *stringLength);
  1455. /// <summary>
  1456. /// Converts the value to string using standard JavaScript semantics.
  1457. /// </summary>
  1458. /// <remarks>
  1459. /// Requires an active script context.
  1460. /// </remarks>
  1461. /// <param name="value">The value to be converted.</param>
  1462. /// <param name="stringValue">The converted value.</param>
  1463. /// <returns>
  1464. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1465. /// </returns>
  1466. STDAPI_(JsErrorCode)
  1467. JsConvertValueToString(
  1468. _In_ JsValueRef value,
  1469. _Out_ JsValueRef *stringValue);
  1470. /// <summary>
  1471. /// Gets the global object in the current script context.
  1472. /// </summary>
  1473. /// <remarks>
  1474. /// Requires an active script context.
  1475. /// </remarks>
  1476. /// <param name="globalObject">The global object.</param>
  1477. /// <returns>
  1478. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1479. /// </returns>
  1480. STDAPI_(JsErrorCode)
  1481. JsGetGlobalObject(
  1482. _Out_ JsValueRef *globalObject);
  1483. /// <summary>
  1484. /// Creates a new object.
  1485. /// </summary>
  1486. /// <remarks>
  1487. /// Requires an active script context.
  1488. /// </remarks>
  1489. /// <param name="object">The new object.</param>
  1490. /// <returns>
  1491. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1492. /// </returns>
  1493. STDAPI_(JsErrorCode)
  1494. JsCreateObject(
  1495. _Out_ JsValueRef *object);
  1496. /// <summary>
  1497. /// A finalizer callback.
  1498. /// </summary>
  1499. /// <param name="data">
  1500. /// The external data that was passed in when creating the object being finalized.
  1501. /// </param>
  1502. typedef void (CALLBACK *JsFinalizeCallback)(_In_opt_ void *data);
  1503. /// <summary>
  1504. /// Creates a new object that stores some external data.
  1505. /// </summary>
  1506. /// <remarks>
  1507. /// Requires an active script context.
  1508. /// </remarks>
  1509. /// <param name="data">External data that the object will represent. May be null.</param>
  1510. /// <param name="finalizeCallback">
  1511. /// A callback for when the object is finalized. May be null.
  1512. /// </param>
  1513. /// <param name="object">The new object.</param>
  1514. /// <returns>
  1515. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1516. /// </returns>
  1517. STDAPI_(JsErrorCode)
  1518. JsCreateExternalObject(
  1519. _In_opt_ void *data,
  1520. _In_opt_ JsFinalizeCallback finalizeCallback,
  1521. _Out_ JsValueRef *object);
  1522. /// <summary>
  1523. /// Converts the value to object using standard JavaScript semantics.
  1524. /// </summary>
  1525. /// <remarks>
  1526. /// Requires an active script context.
  1527. /// </remarks>
  1528. /// <param name="value">The value to be converted.</param>
  1529. /// <param name="object">The converted value.</param>
  1530. /// <returns>
  1531. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1532. /// </returns>
  1533. STDAPI_(JsErrorCode)
  1534. JsConvertValueToObject(
  1535. _In_ JsValueRef value,
  1536. _Out_ JsValueRef *object);
  1537. /// <summary>
  1538. /// Returns the prototype of an object.
  1539. /// </summary>
  1540. /// <remarks>
  1541. /// Requires an active script context.
  1542. /// </remarks>
  1543. /// <param name="object">The object whose prototype is to be returned.</param>
  1544. /// <param name="prototypeObject">The object's prototype.</param>
  1545. /// <returns>
  1546. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1547. /// </returns>
  1548. STDAPI_(JsErrorCode)
  1549. JsGetPrototype(
  1550. _In_ JsValueRef object,
  1551. _Out_ JsValueRef *prototypeObject);
  1552. /// <summary>
  1553. /// Sets the prototype of an object.
  1554. /// </summary>
  1555. /// <remarks>
  1556. /// Requires an active script context.
  1557. /// </remarks>
  1558. /// <param name="object">The object whose prototype is to be changed.</param>
  1559. /// <param name="prototypeObject">The object's new prototype.</param>
  1560. /// <returns>
  1561. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1562. /// </returns>
  1563. STDAPI_(JsErrorCode)
  1564. JsSetPrototype(
  1565. _In_ JsValueRef object,
  1566. _In_ JsValueRef prototypeObject);
  1567. /// <summary>
  1568. /// Performs JavaScript "instanceof" operator test.
  1569. /// </summary>
  1570. /// <remarks>
  1571. /// Requires an active script context.
  1572. /// </remarks>
  1573. /// <param name="object">The object to test.</param>
  1574. /// <param name="constructor">The constructor function to test against.</param>
  1575. /// <param name="result">Whether "object instanceof constructor" is true.</param>
  1576. /// <returns>
  1577. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1578. /// </returns>
  1579. STDAPI_(JsErrorCode)
  1580. JsInstanceOf(
  1581. _In_ JsValueRef object,
  1582. _In_ JsValueRef constructor,
  1583. _Out_ bool *result);
  1584. /// <summary>
  1585. /// Returns a value that indicates whether an object is extensible or not.
  1586. /// </summary>
  1587. /// <remarks>
  1588. /// Requires an active script context.
  1589. /// </remarks>
  1590. /// <param name="object">The object to test.</param>
  1591. /// <param name="value">Whether the object is extensible or not.</param>
  1592. /// <returns>
  1593. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1594. /// </returns>
  1595. STDAPI_(JsErrorCode)
  1596. JsGetExtensionAllowed(
  1597. _In_ JsValueRef object,
  1598. _Out_ bool *value);
  1599. /// <summary>
  1600. /// Makes an object non-extensible.
  1601. /// </summary>
  1602. /// <remarks>
  1603. /// Requires an active script context.
  1604. /// </remarks>
  1605. /// <param name="object">The object to make non-extensible.</param>
  1606. /// <returns>
  1607. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1608. /// </returns>
  1609. STDAPI_(JsErrorCode)
  1610. JsPreventExtension(
  1611. _In_ JsValueRef object);
  1612. /// <summary>
  1613. /// Gets an object's property.
  1614. /// </summary>
  1615. /// <remarks>
  1616. /// Requires an active script context.
  1617. /// </remarks>
  1618. /// <param name="object">The object that contains the property.</param>
  1619. /// <param name="propertyId">The ID of the property.</param>
  1620. /// <param name="value">The value of the property.</param>
  1621. /// <returns>
  1622. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1623. /// </returns>
  1624. STDAPI_(JsErrorCode)
  1625. JsGetProperty(
  1626. _In_ JsValueRef object,
  1627. _In_ JsPropertyIdRef propertyId,
  1628. _Out_ JsValueRef *value);
  1629. /// <summary>
  1630. /// Gets a property descriptor for an object's own property.
  1631. /// </summary>
  1632. /// <remarks>
  1633. /// Requires an active script context.
  1634. /// </remarks>
  1635. /// <param name="object">The object that has the property.</param>
  1636. /// <param name="propertyId">The ID of the property.</param>
  1637. /// <param name="propertyDescriptor">The property descriptor.</param>
  1638. /// <returns>
  1639. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1640. /// </returns>
  1641. STDAPI_(JsErrorCode)
  1642. JsGetOwnPropertyDescriptor(
  1643. _In_ JsValueRef object,
  1644. _In_ JsPropertyIdRef propertyId,
  1645. _Out_ JsValueRef *propertyDescriptor);
  1646. /// <summary>
  1647. /// Gets the list of all properties on the object.
  1648. /// </summary>
  1649. /// <remarks>
  1650. /// Requires an active script context.
  1651. /// </remarks>
  1652. /// <param name="object">The object from which to get the property names.</param>
  1653. /// <param name="propertyNames">An array of property names.</param>
  1654. /// <returns>
  1655. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1656. /// </returns>
  1657. STDAPI_(JsErrorCode)
  1658. JsGetOwnPropertyNames(
  1659. _In_ JsValueRef object,
  1660. _Out_ JsValueRef *propertyNames);
  1661. /// <summary>
  1662. /// Puts an object's property.
  1663. /// </summary>
  1664. /// <remarks>
  1665. /// Requires an active script context.
  1666. /// </remarks>
  1667. /// <param name="object">The object that contains the property.</param>
  1668. /// <param name="propertyId">The ID of the property.</param>
  1669. /// <param name="value">The new value of the property.</param>
  1670. /// <param name="useStrictRules">The property set should follow strict mode rules.</param>
  1671. /// <returns>
  1672. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1673. /// </returns>
  1674. STDAPI_(JsErrorCode)
  1675. JsSetProperty(
  1676. _In_ JsValueRef object,
  1677. _In_ JsPropertyIdRef propertyId,
  1678. _In_ JsValueRef value,
  1679. _In_ bool useStrictRules);
  1680. /// <summary>
  1681. /// Determines whether an object has a property.
  1682. /// </summary>
  1683. /// <remarks>
  1684. /// Requires an active script context.
  1685. /// </remarks>
  1686. /// <param name="object">The object that may contain the property.</param>
  1687. /// <param name="propertyId">The ID of the property.</param>
  1688. /// <param name="hasProperty">Whether the object (or a prototype) has the property.</param>
  1689. /// <returns>
  1690. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1691. /// </returns>
  1692. STDAPI_(JsErrorCode)
  1693. JsHasProperty(
  1694. _In_ JsValueRef object,
  1695. _In_ JsPropertyIdRef propertyId,
  1696. _Out_ bool *hasProperty);
  1697. /// <summary>
  1698. /// Deletes an object's property.
  1699. /// </summary>
  1700. /// <remarks>
  1701. /// Requires an active script context.
  1702. /// </remarks>
  1703. /// <param name="object">The object that contains the property.</param>
  1704. /// <param name="propertyId">The ID of the property.</param>
  1705. /// <param name="useStrictRules">The property set should follow strict mode rules.</param>
  1706. /// <param name="result">Whether the property was deleted.</param>
  1707. /// <returns>
  1708. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1709. /// </returns>
  1710. STDAPI_(JsErrorCode)
  1711. JsDeleteProperty(
  1712. _In_ JsValueRef object,
  1713. _In_ JsPropertyIdRef propertyId,
  1714. _In_ bool useStrictRules,
  1715. _Out_ JsValueRef *result);
  1716. /// <summary>
  1717. /// Defines a new object's own property from a property descriptor.
  1718. /// </summary>
  1719. /// <remarks>
  1720. /// Requires an active script context.
  1721. /// </remarks>
  1722. /// <param name="object">The object that has the property.</param>
  1723. /// <param name="propertyId">The ID of the property.</param>
  1724. /// <param name="propertyDescriptor">The property descriptor.</param>
  1725. /// <param name="result">Whether the property was defined.</param>
  1726. /// <returns>
  1727. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1728. /// </returns>
  1729. STDAPI_(JsErrorCode)
  1730. JsDefineProperty(
  1731. _In_ JsValueRef object,
  1732. _In_ JsPropertyIdRef propertyId,
  1733. _In_ JsValueRef propertyDescriptor,
  1734. _Out_ bool *result);
  1735. /// <summary>
  1736. /// Tests whether an object has a value at the specified index.
  1737. /// </summary>
  1738. /// <remarks>
  1739. /// Requires an active script context.
  1740. /// </remarks>
  1741. /// <param name="object">The object to operate on.</param>
  1742. /// <param name="index">The index to test.</param>
  1743. /// <param name="result">Whether the object has a value at the specified index.</param>
  1744. /// <returns>
  1745. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1746. /// </returns>
  1747. STDAPI_(JsErrorCode)
  1748. JsHasIndexedProperty(
  1749. _In_ JsValueRef object,
  1750. _In_ JsValueRef index,
  1751. _Out_ bool *result);
  1752. /// <summary>
  1753. /// Retrieve the value at the specified index of an object.
  1754. /// </summary>
  1755. /// <remarks>
  1756. /// Requires an active script context.
  1757. /// </remarks>
  1758. /// <param name="object">The object to operate on.</param>
  1759. /// <param name="index">The index to retrieve.</param>
  1760. /// <param name="result">The retrieved value.</param>
  1761. /// <returns>
  1762. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1763. /// </returns>
  1764. STDAPI_(JsErrorCode)
  1765. JsGetIndexedProperty(
  1766. _In_ JsValueRef object,
  1767. _In_ JsValueRef index,
  1768. _Out_ JsValueRef *result);
  1769. /// <summary>
  1770. /// Set the value at the specified index of an object.
  1771. /// </summary>
  1772. /// <remarks>
  1773. /// Requires an active script context.
  1774. /// </remarks>
  1775. /// <param name="object">The object to operate on.</param>
  1776. /// <param name="index">The index to set.</param>
  1777. /// <param name="value">The value to set.</param>
  1778. /// <returns>
  1779. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1780. /// </returns>
  1781. STDAPI_(JsErrorCode)
  1782. JsSetIndexedProperty(
  1783. _In_ JsValueRef object,
  1784. _In_ JsValueRef index,
  1785. _In_ JsValueRef value);
  1786. /// <summary>
  1787. /// Delete the value at the specified index of an object.
  1788. /// </summary>
  1789. /// <remarks>
  1790. /// Requires an active script context.
  1791. /// </remarks>
  1792. /// <param name="object">The object to operate on.</param>
  1793. /// <param name="index">The index to delete.</param>
  1794. /// <returns>
  1795. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1796. /// </returns>
  1797. STDAPI_(JsErrorCode)
  1798. JsDeleteIndexedProperty(
  1799. _In_ JsValueRef object,
  1800. _In_ JsValueRef index);
  1801. /// <summary>
  1802. /// Determines whether an object has its indexed properties in external data.
  1803. /// </summary>
  1804. /// <param name="object">The object.</param>
  1805. /// <param name="value">Whether the object has its indexed properties in external data.</param>
  1806. /// <returns>
  1807. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1808. /// </returns>
  1809. STDAPI_(JsErrorCode)
  1810. JsHasIndexedPropertiesExternalData(
  1811. _In_ JsValueRef object,
  1812. _Out_ bool* value);
  1813. /// <summary>
  1814. /// Retrieves an object's indexed properties external data information.
  1815. /// </summary>
  1816. /// <param name="object">The object.</param>
  1817. /// <param name="data">The external data back store for the object's indexed properties.</param>
  1818. /// <param name="arrayType">The array element type in external data.</param>
  1819. /// <param name="elementLength">The number of array elements in external data.</param>
  1820. /// <returns>
  1821. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1822. /// </returns>
  1823. STDAPI_(JsErrorCode)
  1824. JsGetIndexedPropertiesExternalData(
  1825. _In_ JsValueRef object,
  1826. _Out_ void** data,
  1827. _Out_ JsTypedArrayType* arrayType,
  1828. _Out_ unsigned int* elementLength);
  1829. /// <summary>
  1830. /// Sets an object's indexed properties to external data. The external data will be used as back
  1831. /// store for the object's indexed properties and accessed like a typed array.
  1832. /// </summary>
  1833. /// <remarks>
  1834. /// Requires an active script context.
  1835. /// </remarks>
  1836. /// <param name="object">The object to operate on.</param>
  1837. /// <param name="data">The external data to be used as back store for the object's indexed properties.</param>
  1838. /// <param name="arrayType">The array element type in external data.</param>
  1839. /// <param name="elementLength">The number of array elements in external data.</param>
  1840. /// <returns>
  1841. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1842. /// </returns>
  1843. STDAPI_(JsErrorCode)
  1844. JsSetIndexedPropertiesToExternalData(
  1845. _In_ JsValueRef object,
  1846. _In_ void* data,
  1847. _In_ JsTypedArrayType arrayType,
  1848. _In_ unsigned int elementLength);
  1849. /// <summary>
  1850. /// Compare two JavaScript values for equality.
  1851. /// </summary>
  1852. /// <remarks>
  1853. /// <para>
  1854. /// This function is equivalent to the <c>==</c> operator in Javascript.
  1855. /// </para>
  1856. /// <para>
  1857. /// Requires an active script context.
  1858. /// </para>
  1859. /// </remarks>
  1860. /// <param name="object1">The first object to compare.</param>
  1861. /// <param name="object2">The second object to compare.</param>
  1862. /// <param name="result">Whether the values are equal.</param>
  1863. /// <returns>
  1864. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1865. /// </returns>
  1866. STDAPI_(JsErrorCode)
  1867. JsEquals(
  1868. _In_ JsValueRef object1,
  1869. _In_ JsValueRef object2,
  1870. _Out_ bool *result);
  1871. /// <summary>
  1872. /// Compare two JavaScript values for strict equality.
  1873. /// </summary>
  1874. /// <remarks>
  1875. /// <para>
  1876. /// This function is equivalent to the <c>===</c> operator in Javascript.
  1877. /// </para>
  1878. /// <para>
  1879. /// Requires an active script context.
  1880. /// </para>
  1881. /// </remarks>
  1882. /// <param name="object1">The first object to compare.</param>
  1883. /// <param name="object2">The second object to compare.</param>
  1884. /// <param name="result">Whether the values are strictly equal.</param>
  1885. /// <returns>
  1886. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1887. /// </returns>
  1888. STDAPI_(JsErrorCode)
  1889. JsStrictEquals(
  1890. _In_ JsValueRef object1,
  1891. _In_ JsValueRef object2,
  1892. _Out_ bool *result);
  1893. /// <summary>
  1894. /// Determines whether an object is an external object.
  1895. /// </summary>
  1896. /// <param name="object">The object.</param>
  1897. /// <param name="value">Whether the object is an external object.</param>
  1898. /// <returns>
  1899. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1900. /// </returns>
  1901. STDAPI_(JsErrorCode)
  1902. JsHasExternalData(
  1903. _In_ JsValueRef object,
  1904. _Out_ bool *value);
  1905. /// <summary>
  1906. /// Retrieves the data from an external object.
  1907. /// </summary>
  1908. /// <param name="object">The external object.</param>
  1909. /// <param name="externalData">
  1910. /// The external data stored in the object. Can be null if no external data is stored in the
  1911. /// object.
  1912. /// </param>
  1913. /// <returns>
  1914. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1915. /// </returns>
  1916. STDAPI_(JsErrorCode)
  1917. JsGetExternalData(
  1918. _In_ JsValueRef object,
  1919. _Out_ void **externalData);
  1920. /// <summary>
  1921. /// Sets the external data on an external object.
  1922. /// </summary>
  1923. /// <param name="object">The external object.</param>
  1924. /// <param name="externalData">
  1925. /// The external data to be stored in the object. Can be null if no external data is
  1926. /// to be stored in the object.
  1927. /// </param>
  1928. /// <returns>
  1929. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1930. /// </returns>
  1931. STDAPI_(JsErrorCode)
  1932. JsSetExternalData(
  1933. _In_ JsValueRef object,
  1934. _In_opt_ void *externalData);
  1935. /// <summary>
  1936. /// Creates a Javascript array object.
  1937. /// </summary>
  1938. /// <remarks>
  1939. /// Requires an active script context.
  1940. /// </remarks>
  1941. /// <param name="length">The initial length of the array.</param>
  1942. /// <param name="result">The new array object.</param>
  1943. /// <returns>
  1944. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1945. /// </returns>
  1946. STDAPI_(JsErrorCode)
  1947. JsCreateArray(
  1948. _In_ unsigned int length,
  1949. _Out_ JsValueRef *result);
  1950. /// <summary>
  1951. /// Creates a Javascript ArrayBuffer object.
  1952. /// </summary>
  1953. /// <remarks>
  1954. /// Requires an active script context.
  1955. /// </remarks>
  1956. /// <param name="byteLength">
  1957. /// The number of bytes in the ArrayBuffer.
  1958. /// </param>
  1959. /// <param name="result">The new ArrayBuffer object.</param>
  1960. /// <returns>
  1961. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1962. /// </returns>
  1963. STDAPI_(JsErrorCode)
  1964. JsCreateArrayBuffer(
  1965. _In_ unsigned int byteLength,
  1966. _Out_ JsValueRef *result);
  1967. /// <summary>
  1968. /// Creates a Javascript ArrayBuffer object to access external memory.
  1969. /// </summary>
  1970. /// <remarks>Requires an active script context.</remarks>
  1971. /// <param name="data">A pointer to the external memory.</param>
  1972. /// <param name="byteLength">The number of bytes in the external memory.</param>
  1973. /// <param name="finalizeCallback">A callback for when the object is finalized. May be null.</param>
  1974. /// <param name="callbackState">User provided state that will be passed back to finalizeCallback.</param>
  1975. /// <param name="result">The new ArrayBuffer object.</param>
  1976. /// <returns>
  1977. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1978. /// </returns>
  1979. STDAPI_(JsErrorCode)
  1980. JsCreateExternalArrayBuffer(
  1981. _Pre_maybenull_ _Pre_writable_byte_size_(byteLength) void *data,
  1982. _In_ unsigned int byteLength,
  1983. _In_opt_ JsFinalizeCallback finalizeCallback,
  1984. _In_opt_ void *callbackState,
  1985. _Out_ JsValueRef *result);
  1986. /// <summary>
  1987. /// Creates a Javascript typed array object.
  1988. /// </summary>
  1989. /// <remarks>
  1990. /// <para>
  1991. /// The <c>baseArray</c> can be an <c>ArrayBuffer</c>, another typed array, or a JavaScript
  1992. /// <c>Array</c>. The returned typed array will use the baseArray if it is an ArrayBuffer, or
  1993. /// otherwise create and use a copy of the underlying source array.
  1994. /// </para>
  1995. /// <para>
  1996. /// Requires an active script context.
  1997. /// </para>
  1998. /// </remarks>
  1999. /// <param name="arrayType">The type of the array to create.</param>
  2000. /// <param name="baseArray">
  2001. /// The base array of the new array. Use <c>JS_INVALID_REFERENCE</c> if no base array.
  2002. /// </param>
  2003. /// <param name="byteOffset">
  2004. /// The offset in bytes from the start of baseArray (ArrayBuffer) for result typed array to reference.
  2005. /// Only applicable when baseArray is an ArrayBuffer object. Must be 0 otherwise.
  2006. /// </param>
  2007. /// <param name="elementLength">
  2008. /// The number of elements in the array. Only applicable when creating a new typed array without
  2009. /// baseArray (baseArray is <c>JS_INVALID_REFERENCE</c>) or when baseArray is an ArrayBuffer object.
  2010. /// Must be 0 otherwise.
  2011. /// </param>
  2012. /// <param name="result">The new typed array object.</param>
  2013. /// <returns>
  2014. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2015. /// </returns>
  2016. STDAPI_(JsErrorCode)
  2017. JsCreateTypedArray(
  2018. _In_ JsTypedArrayType arrayType,
  2019. _In_ JsValueRef baseArray,
  2020. _In_ unsigned int byteOffset,
  2021. _In_ unsigned int elementLength,
  2022. _Out_ JsValueRef *result);
  2023. /// <summary>
  2024. /// Creates a Javascript DataView object.
  2025. /// </summary>
  2026. /// <remarks>
  2027. /// Requires an active script context.
  2028. /// </remarks>
  2029. /// <param name="arrayBuffer">
  2030. /// An existing ArrayBuffer object to use as the storage for the result DataView object.
  2031. /// </param>
  2032. /// <param name="byteOffset">
  2033. /// The offset in bytes from the start of arrayBuffer for result DataView to reference.
  2034. /// </param>
  2035. /// <param name="byteLength">
  2036. /// The number of bytes in the ArrayBuffer for result DataView to reference.
  2037. /// </param>
  2038. /// <param name="result">The new DataView object.</param>
  2039. /// <returns>
  2040. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2041. /// </returns>
  2042. STDAPI_(JsErrorCode)
  2043. JsCreateDataView(
  2044. _In_ JsValueRef arrayBuffer,
  2045. _In_ unsigned int byteOffset,
  2046. _In_ unsigned int byteLength,
  2047. _Out_ JsValueRef *result);
  2048. /// <summary>
  2049. /// Obtains frequently used properties of a typed array.
  2050. /// </summary>
  2051. /// <param name="typedArray">The typed array instance.</param>
  2052. /// <param name="arrayType">The type of the array.</param>
  2053. /// <param name="arrayBuffer">The ArrayBuffer backstore of the array.</param>
  2054. /// <param name="byteOffset">The offset in bytes from the start of arrayBuffer referenced by the array.</param>
  2055. /// <param name="byteLength">The number of bytes in the array.</param>
  2056. /// <returns>
  2057. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2058. /// </returns>
  2059. STDAPI_(JsErrorCode)
  2060. JsGetTypedArrayInfo(
  2061. _In_ JsValueRef typedArray,
  2062. _Out_opt_ JsTypedArrayType *arrayType,
  2063. _Out_opt_ JsValueRef *arrayBuffer,
  2064. _Out_opt_ unsigned int *byteOffset,
  2065. _Out_opt_ unsigned int *byteLength);
  2066. /// <summary>
  2067. /// Obtains the underlying memory storage used by an <c>ArrayBuffer</c>.
  2068. /// </summary>
  2069. /// <param name="arrayBuffer">The ArrayBuffer instance.</param>
  2070. /// <param name="buffer">
  2071. /// The ArrayBuffer's buffer. The lifetime of the buffer returned is the same as the lifetime of the
  2072. /// the ArrayBuffer. The buffer pointer does not count as a reference to the ArrayBuffer for the purpose
  2073. /// of garbage collection.
  2074. /// </param>
  2075. /// <param name="bufferLength">The number of bytes in the buffer.</param>
  2076. /// <returns>
  2077. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2078. /// </returns>
  2079. STDAPI_(JsErrorCode)
  2080. JsGetArrayBufferStorage(
  2081. _In_ JsValueRef arrayBuffer,
  2082. _Outptr_result_bytebuffer_(*bufferLength) BYTE **buffer,
  2083. _Out_ unsigned int *bufferLength);
  2084. /// <summary>
  2085. /// Obtains the underlying memory storage used by a typed array.
  2086. /// </summary>
  2087. /// <param name="typedArray">The typed array instance.</param>
  2088. /// <param name="buffer">
  2089. /// The array's buffer. The lifetime of the buffer returned is the same as the lifetime of the
  2090. /// the array. The buffer pointer does not count as a reference to the array for the purpose
  2091. /// of garbage collection.
  2092. /// </param>
  2093. /// <param name="bufferLength">The number of bytes in the buffer.</param>
  2094. /// <param name="arrayType">The type of the array.</param>
  2095. /// <param name="elementSize">
  2096. /// The size of an element of the array.
  2097. /// </param>
  2098. /// <returns>
  2099. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2100. /// </returns>
  2101. STDAPI_(JsErrorCode)
  2102. JsGetTypedArrayStorage(
  2103. _In_ JsValueRef typedArray,
  2104. _Outptr_result_bytebuffer_(*bufferLength) BYTE **buffer,
  2105. _Out_ unsigned int *bufferLength,
  2106. _Out_opt_ JsTypedArrayType *arrayType,
  2107. _Out_opt_ int *elementSize);
  2108. /// <summary>
  2109. /// Obtains the underlying memory storage used by a DataView.
  2110. /// </summary>
  2111. /// <param name="dataView">The DataView instance.</param>
  2112. /// <param name="buffer">
  2113. /// The DataView's buffer. The lifetime of the buffer returned is the same as the lifetime of the
  2114. /// the DataView. The buffer pointer does not count as a reference to the DataView for the purpose
  2115. /// of garbage collection.
  2116. /// </param>
  2117. /// <param name="bufferLength">The number of bytes in the buffer.</param>
  2118. /// <returns>
  2119. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2120. /// </returns>
  2121. STDAPI_(JsErrorCode)
  2122. JsGetDataViewStorage(
  2123. _In_ JsValueRef dataView,
  2124. _Outptr_result_bytebuffer_(*bufferLength) BYTE **buffer,
  2125. _Out_ unsigned int *bufferLength);
  2126. /// <summary>
  2127. /// Invokes a function.
  2128. /// </summary>
  2129. /// <remarks>
  2130. /// Requires thisArg as first argument of arguments.
  2131. /// Requires an active script context.
  2132. /// </remarks>
  2133. /// <param name="function">The function to invoke.</param>
  2134. /// <param name="arguments">The arguments to the call.</param>
  2135. /// <param name="argumentCount">The number of arguments being passed in to the function.</param>
  2136. /// <param name="result">The value returned from the function invocation, if any.</param>
  2137. /// <returns>
  2138. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2139. /// </returns>
  2140. STDAPI_(JsErrorCode)
  2141. JsCallFunction(
  2142. _In_ JsValueRef function,
  2143. _In_reads_(argumentCount) JsValueRef *arguments,
  2144. _In_ unsigned short argumentCount,
  2145. _Out_opt_ JsValueRef *result);
  2146. /// <summary>
  2147. /// Invokes a function as a constructor.
  2148. /// </summary>
  2149. /// <remarks>
  2150. /// Requires an active script context.
  2151. /// </remarks>
  2152. /// <param name="function">The function to invoke as a constructor.</param>
  2153. /// <param name="arguments">The arguments to the call.</param>
  2154. /// <param name="argumentCount">The number of arguments being passed in to the function.</param>
  2155. /// <param name="result">The value returned from the function invocation.</param>
  2156. /// <returns>
  2157. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2158. /// </returns>
  2159. STDAPI_(JsErrorCode)
  2160. JsConstructObject(
  2161. _In_ JsValueRef function,
  2162. _In_reads_(argumentCount) JsValueRef *arguments,
  2163. _In_ unsigned short argumentCount,
  2164. _Out_ JsValueRef *result);
  2165. /// <summary>
  2166. /// A function callback.
  2167. /// </summary>
  2168. /// <param name="callee">
  2169. /// A function object that represents the function being invoked.
  2170. /// </param>
  2171. /// <param name="isConstructCall">Indicates whether this is a regular call or a 'new' call.</param>
  2172. /// <param name="arguments">The arguments to the call.</param>
  2173. /// <param name="argumentCount">The number of arguments.</param>
  2174. /// <param name="callbackState">
  2175. /// The state passed to <c>JsCreateFunction</c>.
  2176. /// </param>
  2177. /// <returns>The result of the call, if any.</returns>
  2178. typedef _Ret_maybenull_ JsValueRef(CALLBACK * JsNativeFunction)(_In_ JsValueRef callee, _In_ bool isConstructCall, _In_ JsValueRef *arguments, _In_ unsigned short argumentCount, _In_opt_ void *callbackState);
  2179. /// <summary>
  2180. /// Creates a new JavaScript function.
  2181. /// </summary>
  2182. /// <remarks>
  2183. /// Requires an active script context.
  2184. /// </remarks>
  2185. /// <param name="nativeFunction">The method to call when the function is invoked.</param>
  2186. /// <param name="callbackState">
  2187. /// User provided state that will be passed back to the callback.
  2188. /// </param>
  2189. /// <param name="function">The new function object.</param>
  2190. /// <returns>
  2191. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2192. /// </returns>
  2193. STDAPI_(JsErrorCode)
  2194. JsCreateFunction(
  2195. _In_ JsNativeFunction nativeFunction,
  2196. _In_opt_ void *callbackState,
  2197. _Out_ JsValueRef *function);
  2198. /// <summary>
  2199. /// Creates a new JavaScript function with name.
  2200. /// </summary>
  2201. /// <remarks>
  2202. /// Requires an active script context.
  2203. /// </remarks>
  2204. /// <param name="name">The name of this function that will be used for diagnostics and stringification purposes.</param>
  2205. /// <param name="nativeFunction">The method to call when the function is invoked.</param>
  2206. /// <param name="callbackState">
  2207. /// User provided state that will be passed back to the callback.
  2208. /// </param>
  2209. /// <param name="function">The new function object.</param>
  2210. /// <returns>
  2211. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2212. /// </returns>
  2213. STDAPI_(JsErrorCode)
  2214. JsCreateNamedFunction(
  2215. _In_ JsValueRef name,
  2216. _In_ JsNativeFunction nativeFunction,
  2217. _In_opt_ void *callbackState,
  2218. _Out_ JsValueRef *function);
  2219. /// <summary>
  2220. /// Creates a new JavaScript error object
  2221. /// </summary>
  2222. /// <remarks>
  2223. /// Requires an active script context.
  2224. /// </remarks>
  2225. /// <param name="message">Message for the error object.</param>
  2226. /// <param name="error">The new error object.</param>
  2227. /// <returns>
  2228. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2229. /// </returns>
  2230. STDAPI_(JsErrorCode)
  2231. JsCreateError(
  2232. _In_ JsValueRef message,
  2233. _Out_ JsValueRef *error);
  2234. /// <summary>
  2235. /// Creates a new JavaScript RangeError error object
  2236. /// </summary>
  2237. /// <remarks>
  2238. /// Requires an active script context.
  2239. /// </remarks>
  2240. /// <param name="message">Message for the error object.</param>
  2241. /// <param name="error">The new error object.</param>
  2242. /// <returns>
  2243. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2244. /// </returns>
  2245. STDAPI_(JsErrorCode)
  2246. JsCreateRangeError(
  2247. _In_ JsValueRef message,
  2248. _Out_ JsValueRef *error);
  2249. /// <summary>
  2250. /// Creates a new JavaScript ReferenceError error object
  2251. /// </summary>
  2252. /// <remarks>
  2253. /// Requires an active script context.
  2254. /// </remarks>
  2255. /// <param name="message">Message for the error object.</param>
  2256. /// <param name="error">The new error object.</param>
  2257. /// <returns>
  2258. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2259. /// </returns>
  2260. STDAPI_(JsErrorCode)
  2261. JsCreateReferenceError(
  2262. _In_ JsValueRef message,
  2263. _Out_ JsValueRef *error);
  2264. /// <summary>
  2265. /// Creates a new JavaScript SyntaxError error object
  2266. /// </summary>
  2267. /// <remarks>
  2268. /// Requires an active script context.
  2269. /// </remarks>
  2270. /// <param name="message">Message for the error object.</param>
  2271. /// <param name="error">The new error object.</param>
  2272. /// <returns>
  2273. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2274. /// </returns>
  2275. STDAPI_(JsErrorCode)
  2276. JsCreateSyntaxError(
  2277. _In_ JsValueRef message,
  2278. _Out_ JsValueRef *error);
  2279. /// <summary>
  2280. /// Creates a new JavaScript TypeError error object
  2281. /// </summary>
  2282. /// <remarks>
  2283. /// Requires an active script context.
  2284. /// </remarks>
  2285. /// <param name="message">Message for the error object.</param>
  2286. /// <param name="error">The new error object.</param>
  2287. /// <returns>
  2288. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2289. /// </returns>
  2290. STDAPI_(JsErrorCode)
  2291. JsCreateTypeError(
  2292. _In_ JsValueRef message,
  2293. _Out_ JsValueRef *error);
  2294. /// <summary>
  2295. /// Creates a new JavaScript URIError error object
  2296. /// </summary>
  2297. /// <remarks>
  2298. /// Requires an active script context.
  2299. /// </remarks>
  2300. /// <param name="message">Message for the error object.</param>
  2301. /// <param name="error">The new error object.</param>
  2302. /// <returns>
  2303. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2304. /// </returns>
  2305. STDAPI_(JsErrorCode)
  2306. JsCreateURIError(
  2307. _In_ JsValueRef message,
  2308. _Out_ JsValueRef *error);
  2309. /// <summary>
  2310. /// Determines whether the runtime of the current context is in an exception state.
  2311. /// </summary>
  2312. /// <remarks>
  2313. /// <para>
  2314. /// If a call into the runtime results in an exception (either as the result of running a
  2315. /// script or due to something like a conversion failure), the runtime is placed into an
  2316. /// "exception state." All calls into any context created by the runtime (except for the
  2317. /// exception APIs) will fail with <c>JsErrorInExceptionState</c> until the exception is
  2318. /// cleared.
  2319. /// </para>
  2320. /// <para>
  2321. /// If the runtime of the current context is in the exception state when a callback returns
  2322. /// into the engine, the engine will automatically rethrow the exception.
  2323. /// </para>
  2324. /// <para>
  2325. /// Requires an active script context.
  2326. /// </para>
  2327. /// </remarks>
  2328. /// <param name="hasException">
  2329. /// Whether the runtime of the current context is in the exception state.
  2330. /// </param>
  2331. /// <returns>
  2332. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2333. /// </returns>
  2334. STDAPI_(JsErrorCode)
  2335. JsHasException(
  2336. _Out_ bool *hasException);
  2337. /// <summary>
  2338. /// Returns the exception that caused the runtime of the current context to be in the
  2339. /// exception state and resets the exception state for that runtime.
  2340. /// </summary>
  2341. /// <remarks>
  2342. /// <para>
  2343. /// If the runtime of the current context is not in an exception state, this API will return
  2344. /// <c>JsErrorInvalidArgument</c>. If the runtime is disabled, this will return an exception
  2345. /// indicating that the script was terminated, but it will not clear the exception (the
  2346. /// exception will be cleared if the runtime is re-enabled using
  2347. /// <c>JsEnableRuntimeExecution</c>).
  2348. /// </para>
  2349. /// <para>
  2350. /// Requires an active script context.
  2351. /// </para>
  2352. /// </remarks>
  2353. /// <param name="exception">The exception for the runtime of the current context.</param>
  2354. /// <returns>
  2355. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2356. /// </returns>
  2357. STDAPI_(JsErrorCode)
  2358. JsGetAndClearException(
  2359. _Out_ JsValueRef *exception);
  2360. /// <summary>
  2361. /// Sets the runtime of the current context to an exception state.
  2362. /// </summary>
  2363. /// <remarks>
  2364. /// <para>
  2365. /// If the runtime of the current context is already in an exception state, this API will
  2366. /// return <c>JsErrorInExceptionState</c>.
  2367. /// </para>
  2368. /// <para>
  2369. /// Requires an active script context.
  2370. /// </para>
  2371. /// </remarks>
  2372. /// <param name="exception">
  2373. /// The JavaScript exception to set for the runtime of the current context.
  2374. /// </param>
  2375. /// <returns>
  2376. /// JsNoError if the engine was set into an exception state, a failure code otherwise.
  2377. /// </returns>
  2378. STDAPI_(JsErrorCode)
  2379. JsSetException(
  2380. _In_ JsValueRef exception);
  2381. /// <summary>
  2382. /// Suspends script execution and terminates any running scripts in a runtime.
  2383. /// </summary>
  2384. /// <remarks>
  2385. /// <para>
  2386. /// Calls to a suspended runtime will fail until <c>JsEnableRuntimeExecution</c> is called.
  2387. /// </para>
  2388. /// <para>
  2389. /// This API does not have to be called on the thread the runtime is active on. Although the
  2390. /// runtime will be set into a suspended state, an executing script may not be suspended
  2391. /// immediately; a running script will be terminated with an uncatchable exception as soon as
  2392. /// possible.
  2393. /// </para>
  2394. /// <para>
  2395. /// Suspending execution in a runtime that is already suspended is a no-op.
  2396. /// </para>
  2397. /// </remarks>
  2398. /// <param name="runtime">The runtime to be suspended.</param>
  2399. /// <returns>
  2400. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2401. /// </returns>
  2402. STDAPI_(JsErrorCode)
  2403. JsDisableRuntimeExecution(
  2404. _In_ JsRuntimeHandle runtime);
  2405. /// <summary>
  2406. /// Enables script execution in a runtime.
  2407. /// </summary>
  2408. /// <remarks>
  2409. /// Enabling script execution in a runtime that already has script execution enabled is a
  2410. /// no-op.
  2411. /// </remarks>
  2412. /// <param name="runtime">The runtime to be enabled.</param>
  2413. /// <returns>
  2414. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2415. /// </returns>
  2416. STDAPI_(JsErrorCode)
  2417. JsEnableRuntimeExecution(
  2418. _In_ JsRuntimeHandle runtime);
  2419. /// <summary>
  2420. /// Returns a value that indicates whether script execution is disabled in the runtime.
  2421. /// </summary>
  2422. /// <param name="runtime">Specifies the runtime to check if execution is disabled.</param>
  2423. /// <param name="isDisabled">If execution is disabled, <c>true</c>, <c>false</c> otherwise.</param>
  2424. /// <returns>
  2425. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2426. /// </returns>
  2427. STDAPI_(JsErrorCode)
  2428. JsIsRuntimeExecutionDisabled(
  2429. _In_ JsRuntimeHandle runtime,
  2430. _Out_ bool *isDisabled);
  2431. /// <summary>
  2432. /// A promise continuation callback.
  2433. /// </summary>
  2434. /// <remarks>
  2435. /// The host can specify a promise continuation callback in <c>JsSetPromiseContinuationCallback</c>. If
  2436. /// a script creates a task to be run later, then the promise continuation callback will be called with
  2437. /// the task and the task should be put in a FIFO queue, to be run when the current script is
  2438. /// done executing.
  2439. /// </remarks>
  2440. /// <param name="task">The task, represented as a JavaScript function.</param>
  2441. /// <param name="callbackState">The data argument to be passed to the callback.</param>
  2442. typedef void (CALLBACK *JsPromiseContinuationCallback)(_In_ JsValueRef task, _In_opt_ void *callbackState);
  2443. /// <summary>
  2444. /// Sets a promise continuation callback function that is called by the context when a task
  2445. /// needs to be queued for future execution
  2446. /// </summary>
  2447. /// <remarks>
  2448. /// <para>
  2449. /// Requires an active script context.
  2450. /// </para>
  2451. /// </remarks>
  2452. /// <param name="promiseContinuationCallback">The callback function being set.</param>
  2453. /// <param name="callbackState">
  2454. /// User provided state that will be passed back to the callback.
  2455. /// </param>
  2456. /// <returns>
  2457. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  2458. /// </returns>
  2459. STDAPI_(JsErrorCode)
  2460. JsSetPromiseContinuationCallback(
  2461. _In_ JsPromiseContinuationCallback promiseContinuationCallback,
  2462. _In_opt_ void *callbackState);
  2463. #endif // _CHAKRACOMMON_H_