2
0

ChakraCommon.h 95 KB

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