ChakraCommon.h 91 KB

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