ChakraCommon.h 92 KB

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