ChakraCommon.h 90 KB

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