ChakraCommon.h 91 KB

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