ChakraCore.h 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026
  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. /// \file
  12. /// \brief The Chakra Core hosting API.
  13. ///
  14. /// This file contains a flat C API layer. This is the API exported by ChakraCore.dll.
  15. #ifdef _MSC_VER
  16. #pragma once
  17. #endif // _MSC_VER
  18. #ifndef _CHAKRACORE_H_
  19. #define _CHAKRACORE_H_
  20. #if !defined(NTBUILD) && !defined(_CHAKRACOREBUILD)
  21. #define _CHAKRACOREBUILD
  22. #endif
  23. #include "ChakraCommon.h"
  24. #include "ChakraDebug.h"
  25. // Begin ChakraCore only APIs
  26. #ifdef _CHAKRACOREBUILD
  27. /// <summary>
  28. /// A reference to an ES module.
  29. /// </summary>
  30. /// <remarks>
  31. /// A module record represents an ES module.
  32. /// </remarks>
  33. typedef void* JsModuleRecord;
  34. /// <summary>
  35. /// A reference to an object owned by the SharedArrayBuffer.
  36. /// </summary>
  37. /// <remarks>
  38. /// This represents SharedContents which is heap allocated object, it can be passed through
  39. /// different runtimes to share the underlying buffer.
  40. /// </remarks>
  41. typedef void *JsSharedArrayBufferContentHandle;
  42. /// <summary>
  43. /// A reference to a SCA Serializer.
  44. /// </summary>
  45. /// <remarks>
  46. /// This represents the internal state of a Serializer
  47. /// </remarks>
  48. typedef void *JsVarSerializerHandle;
  49. /// <summary>
  50. /// A reference to a SCA Deserializer.
  51. /// </summary>
  52. /// <remarks>
  53. /// This represents the internal state of a Deserializer
  54. /// </remarks>
  55. typedef void *JsVarDeserializerHandle;
  56. /// <summary>
  57. /// Flags for parsing a module.
  58. /// </summary>
  59. typedef enum JsParseModuleSourceFlags
  60. {
  61. /// <summary>
  62. /// Module source is UTF16.
  63. /// </summary>
  64. JsParseModuleSourceFlags_DataIsUTF16LE = 0x00000000,
  65. /// <summary>
  66. /// Module source is UTF8.
  67. /// </summary>
  68. JsParseModuleSourceFlags_DataIsUTF8 = 0x00000001
  69. } JsParseModuleSourceFlags;
  70. /// <summary>
  71. /// The types of host info that can be set on a module record with JsSetModuleHostInfo.
  72. /// </summary>
  73. /// <remarks>
  74. /// For more information see JsSetModuleHostInfo.
  75. /// </remarks>
  76. typedef enum JsModuleHostInfoKind
  77. {
  78. /// <summary>
  79. /// An exception object - e.g. if the module file cannot be found.
  80. /// </summary>
  81. JsModuleHostInfo_Exception = 0x01,
  82. /// <summary>
  83. /// Host defined info.
  84. /// </summary>
  85. JsModuleHostInfo_HostDefined = 0x02,
  86. /// <summary>
  87. /// Callback for receiving notification when module is ready.
  88. /// </summary>
  89. JsModuleHostInfo_NotifyModuleReadyCallback = 0x3,
  90. /// <summary>
  91. /// Callback for receiving notification to fetch a dependent module.
  92. /// </summary>
  93. JsModuleHostInfo_FetchImportedModuleCallback = 0x4,
  94. /// <summary>
  95. /// Callback for receiving notification for calls to ```import()```
  96. /// </summary>
  97. JsModuleHostInfo_FetchImportedModuleFromScriptCallback = 0x5,
  98. /// <summary>
  99. /// URL for use in error stack traces and debugging.
  100. /// </summary>
  101. JsModuleHostInfo_Url = 0x6,
  102. /// <summary>
  103. /// Callback to allow host to initialize import.meta object properties.
  104. /// </summary>
  105. JsModuleHostInfo_InitializeImportMetaCallback = 0x7,
  106. /// <summary>
  107. /// Callback to report module completion or exception thrown when evaluating a module.
  108. /// </summary>
  109. JsModuleHostInfo_ReportModuleCompletionCallback = 0x8
  110. } JsModuleHostInfoKind;
  111. /// <summary>
  112. /// The possible states for a Promise object.
  113. /// </summary>
  114. typedef enum _JsPromiseState
  115. {
  116. JsPromiseStatePending = 0x0,
  117. JsPromiseStateFulfilled = 0x1,
  118. JsPromiseStateRejected = 0x2
  119. } JsPromiseState;
  120. /// <summary>
  121. /// User implemented callback to fetch additional imported modules in ES modules.
  122. /// </summary>
  123. /// <remarks>
  124. /// The callback is invoked on the current runtime execution thread, therefore execution is blocked until
  125. /// the callback completes. Notify the host to fetch the dependent module. This is the "import" part
  126. /// before HostResolveImportedModule in ES6 spec. This notifies the host that the referencing module has
  127. /// the specified module dependency, and the host needs to retrieve the module back.
  128. ///
  129. /// Callback should:
  130. /// 1. Check if the requested module has been requested before - if yes return the existing
  131. /// module record
  132. /// 2. If no create and initialize a new module record with JsInitializeModuleRecord to
  133. /// return and schedule a call to JsParseModuleSource for the new record.
  134. /// </remarks>
  135. /// <param name="referencingModule">The referencing module that is requesting the dependent module.</param>
  136. /// <param name="specifier">The specifier coming from the module source code.</param>
  137. /// <param name="dependentModuleRecord">The ModuleRecord of the dependent module. If the module was requested
  138. /// before from other source, return the existing ModuleRecord, otherwise
  139. /// return a newly created ModuleRecord.</param>
  140. /// <returns>
  141. /// Returns a <c>JsNoError</c> if the operation succeeded an error code otherwise.
  142. /// </returns>
  143. typedef JsErrorCode(CHAKRA_CALLBACK * FetchImportedModuleCallBack)(_In_ JsModuleRecord referencingModule, _In_ JsValueRef specifier, _Outptr_result_maybenull_ JsModuleRecord* dependentModuleRecord);
  144. /// <summary>
  145. /// User implemented callback to fetch imported modules dynamically in scripts.
  146. /// </summary>
  147. /// <remarks>
  148. /// The callback is invoked on the current runtime execution thread, therefore execution is blocked until
  149. /// the callback completes. Notify the host to fetch the dependent module. This is used for the dynamic
  150. /// import() syntax.
  151. ///
  152. /// Callback should:
  153. /// 1. Check if the requested module has been requested before - if yes return the existing module record
  154. /// 2. If no create and initialize a new module record with JsInitializeModuleRecord to return and
  155. /// schedule a call to JsParseModuleSource for the new record.
  156. /// </remarks>
  157. /// <param name="dwReferencingSourceContext">The referencing script context that calls import()</param>
  158. /// <param name="specifier">The specifier provided to the import() call.</param>
  159. /// <param name="dependentModuleRecord">The ModuleRecord of the dependent module. If the module was requested
  160. /// before from other source, return the existing ModuleRecord, otherwise
  161. /// return a newly created ModuleRecord.</param>
  162. /// <returns>
  163. /// Returns <c>JsNoError</c> if the operation succeeded or an error code otherwise.
  164. /// </returns>
  165. typedef JsErrorCode(CHAKRA_CALLBACK * FetchImportedModuleFromScriptCallBack)(_In_ JsSourceContext dwReferencingSourceContext, _In_ JsValueRef specifier, _Outptr_result_maybenull_ JsModuleRecord* dependentModuleRecord);
  166. /// <summary>
  167. /// User implemented callback to get notification when the module is ready.
  168. /// </summary>
  169. /// <remarks>
  170. /// The callback is invoked on the current runtime execution thread, therefore execution is blocked until the
  171. /// callback completes. This callback should schedule a call to JsEvaluateModule to run the module that has been loaded.
  172. /// </remarks>
  173. /// <param name="referencingModule">The referencing module that has finished running ModuleDeclarationInstantiation step.</param>
  174. /// <param name="exceptionVar">If nullptr, the module is successfully initialized and host should queue the execution job
  175. /// otherwise it's the exception object.</param>
  176. /// <returns>
  177. /// Returns a JsErrorCode - note, the return value is ignored.
  178. /// </returns>
  179. typedef JsErrorCode(CHAKRA_CALLBACK * NotifyModuleReadyCallback)(_In_opt_ JsModuleRecord referencingModule, _In_opt_ JsValueRef exceptionVar);
  180. /// <summary>
  181. /// User implemented callback to fill in module properties for the import.meta object.
  182. /// </summary>
  183. /// <remarks>
  184. /// This callback allows the host to fill module details for the referencing module in the import.meta object
  185. /// loaded by script.
  186. /// The callback is invoked on the current runtime execution thread, therefore execution is blocked until the
  187. /// callback completes.
  188. /// </remarks>
  189. /// <param name="referencingModule">The referencing module that is loading an import.meta object.</param>
  190. /// <param name="importMetaVar">The object which will be returned to script for the referencing module.</param>
  191. /// <returns>
  192. /// Returns a JsErrorCode - note, the return value is ignored.
  193. /// </returns>
  194. typedef JsErrorCode(CHAKRA_CALLBACK * InitializeImportMetaCallback)(_In_opt_ JsModuleRecord referencingModule, _In_opt_ JsValueRef importMetaVar);
  195. /// <summary>
  196. /// User implemented callback to report completion of module execution.
  197. /// </summary>
  198. /// <remarks>
  199. /// This callback is used to report the completion of module execution and to report any runtime exceptions.
  200. /// Note it is not used for dynamicly imported modules import() as the reuslt from those are handled with a
  201. /// promise.
  202. /// If this callback is not set and a module produces an exception:
  203. /// a) a purely synchronous module tree with an exception will set the exception on the runtime
  204. /// (this is not done if this callback is set)
  205. /// b) an exception in an asynchronous module tree will not be reported directly.
  206. ///
  207. /// However in all cases the exception will be set on the JsModuleRecord.
  208. /// </remarks>
  209. /// <param name="module">The root module that has completed either with an exception or normally.</param>
  210. /// <param name="exception">The exception object which was thrown or nullptr if the module had a normal completion.</param>
  211. /// <returns>
  212. /// Returns a JsErrorCode: JsNoError if successful.
  213. /// </returns>
  214. typedef JsErrorCode(CHAKRA_CALLBACK * ReportModuleCompletionCallback)(_In_ JsModuleRecord module, _In_opt_ JsValueRef exception);
  215. /// <summary>
  216. /// A structure containing information about a native function callback.
  217. /// </summary>
  218. typedef struct JsNativeFunctionInfo
  219. {
  220. JsValueRef thisArg;
  221. JsValueRef newTargetArg;
  222. bool isConstructCall;
  223. }JsNativeFunctionInfo;
  224. /// <summary>
  225. /// A function callback.
  226. /// </summary>
  227. /// <param name="callee">
  228. /// A function object that represents the function being invoked.
  229. /// </param>
  230. /// <param name="arguments">The arguments to the call.</param>
  231. /// <param name="argumentCount">The number of arguments.</param>
  232. /// <param name="info">Additional information about this function call.</param>
  233. /// <param name="callbackState">
  234. /// The state passed to <c>JsCreateFunction</c>.
  235. /// </param>
  236. /// <returns>The result of the call, if any.</returns>
  237. typedef _Ret_maybenull_ JsValueRef(CHAKRA_CALLBACK * JsEnhancedNativeFunction)(_In_ JsValueRef callee, _In_ JsValueRef *arguments, _In_ unsigned short argumentCount, _In_ JsNativeFunctionInfo *info, _In_opt_ void *callbackState);
  238. /// <summary>
  239. /// A Promise Rejection Tracker callback.
  240. /// </summary>
  241. /// <remarks>
  242. /// The host can specify a promise rejection tracker callback in <c>JsSetHostPromiseRejectionTracker</c>.
  243. /// If a promise is rejected with no reactions or a reaction is added to a promise that was rejected
  244. /// before it had reactions by default nothing is done.
  245. /// A Promise Rejection Tracker callback may be set - which will then be called when this occurs.
  246. /// Note - per draft ECMASpec 2018 25.4.1.9 this function should not set or return an exception
  247. /// Note also the promise and reason parameters may be garbage collected after this function is called
  248. /// if you wish to make further use of them you will need to use JsAddRef to preserve them
  249. /// However if you use JsAddRef you must also call JsRelease and not hold unto them after
  250. /// a handled notification (both per spec and to avoid memory leaks)
  251. /// </remarks>
  252. /// <param name="promise">The promise object, represented as a JsValueRef.</param>
  253. /// <param name="reason">The value/cause of the rejection, represented as a JsValueRef.</param>
  254. /// <param name="handled">Boolean - false for promiseRejected: i.e. if the promise has just been rejected with no handler,
  255. /// true for promiseHandled: i.e. if it was rejected before without a handler and is now being handled.</param>
  256. /// <param name="callbackState">The state passed to <c>JsSetHostPromiseRejectionTracker</c>.</param>
  257. typedef void (CHAKRA_CALLBACK *JsHostPromiseRejectionTrackerCallback)(_In_ JsValueRef promise, _In_ JsValueRef reason, _In_ bool handled, _In_opt_ void *callbackState);
  258. /// <summary>
  259. /// A structure containing information about interceptors.
  260. /// </summary>
  261. typedef struct _JsGetterSetterInterceptor {
  262. JsValueRef getTrap;
  263. JsValueRef setTrap;
  264. JsValueRef deletePropertyTrap;
  265. JsValueRef enumerateTrap;
  266. JsValueRef ownKeysTrap;
  267. JsValueRef hasTrap;
  268. JsValueRef getOwnPropertyDescriptorTrap;
  269. JsValueRef definePropertyTrap;
  270. JsValueRef initializerTrap;
  271. } JsGetterSetterInterceptor;
  272. /// <summary>
  273. /// A callback for tracing references back from Chakra to DOM wrappers.
  274. /// </summary>
  275. typedef void (CHAKRA_CALLBACK *JsDOMWrapperTracingCallback)(_In_opt_ void *data);
  276. /// <summary>
  277. /// A callback for checking whether tracing from Chakra to DOM wrappers has completed.
  278. /// </summary>
  279. typedef bool (CHAKRA_CALLBACK *JsDOMWrapperTracingDoneCallback)(_In_opt_ void *data);
  280. /// <summary>
  281. /// A callback for entering final pause for tracing DOM wrappers.
  282. /// </summary>
  283. typedef void(CHAKRA_CALLBACK *JsDOMWrapperTracingEnterFinalPauseCallback)(_In_opt_ void *data);
  284. /// <summary>
  285. /// A trace callback.
  286. /// </summary>
  287. /// <param name="data">
  288. /// The external data that was passed in when creating the object being traced.
  289. /// </param>
  290. typedef void (CHAKRA_CALLBACK *JsTraceCallback)(_In_opt_ void *data);
  291. /// <summary>
  292. /// Creates a new enhanced JavaScript function.
  293. /// </summary>
  294. /// <remarks>
  295. /// Requires an active script context.
  296. /// </remarks>
  297. /// <param name="nativeFunction">The method to call when the function is invoked.</param>
  298. /// <param name="metadata">If this is not <c>JS_INVALID_REFERENCE</c>, it is converted to a string and used as the name of the function.</param>
  299. /// <param name="callbackState">
  300. /// User provided state that will be passed back to the callback.
  301. /// </param>
  302. /// <param name="function">The new function object.</param>
  303. /// <returns>
  304. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  305. /// </returns>
  306. CHAKRA_API
  307. JsCreateEnhancedFunction(
  308. _In_ JsEnhancedNativeFunction nativeFunction,
  309. _In_opt_ JsValueRef metadata,
  310. _In_opt_ void *callbackState,
  311. _Out_ JsValueRef *function);
  312. /// <summary>
  313. /// Initialize a ModuleRecord from host
  314. /// </summary>
  315. /// <remarks>
  316. /// Bootstrap the module loading process by creating a new module record.
  317. /// </remarks>
  318. /// <param name="referencingModule">Unused parameter - exists for backwards compatability, supply nullptr</param>
  319. /// <param name="normalizedSpecifier">The normalized specifier or url for the module - used in script errors, optional.</param>
  320. /// <param name="moduleRecord">The new module record.</param>
  321. /// <returns>
  322. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  323. /// </returns>
  324. CHAKRA_API
  325. JsInitializeModuleRecord(
  326. _In_opt_ JsModuleRecord referencingModule,
  327. _In_opt_ JsValueRef normalizedSpecifier,
  328. _Outptr_result_maybenull_ JsModuleRecord* moduleRecord);
  329. /// <summary>
  330. /// Parse the source for an ES module
  331. /// </summary>
  332. /// <remarks>
  333. /// This is basically ParseModule operation in ES6 spec. It is slightly different in that:
  334. /// a) The ModuleRecord was initialized earlier, and passed in as an argument.
  335. /// b) This includes a check to see if the module being Parsed is the last module in the
  336. /// dependency tree. If it is it automatically triggers Module Instantiation.
  337. /// </remarks>
  338. /// <param name="requestModule">The ModuleRecord being parsed.</param>
  339. /// <param name="sourceContext">A cookie identifying the script that can be used by debuggable script contexts.</param>
  340. /// <param name="script">The source script to be parsed, but not executed in this code.</param>
  341. /// <param name="scriptLength">The length of sourceText in bytes. As the input might contain a embedded null.</param>
  342. /// <param name="sourceFlag">The type of the source code passed in. It could be utf16 or utf8 at this time.</param>
  343. /// <param name="exceptionValueRef">The error object if there is parse error.</param>
  344. /// <returns>
  345. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  346. /// </returns>
  347. CHAKRA_API
  348. JsParseModuleSource(
  349. _In_ JsModuleRecord requestModule,
  350. _In_ JsSourceContext sourceContext,
  351. _In_ BYTE* script,
  352. _In_ unsigned int scriptLength,
  353. _In_ JsParseModuleSourceFlags sourceFlag,
  354. _Outptr_result_maybenull_ JsValueRef* exceptionValueRef);
  355. /// <summary>
  356. /// Execute module code.
  357. /// </summary>
  358. /// <remarks>
  359. /// This method implements 15.2.1.1.6.5, "ModuleEvaluation" concrete method.
  360. /// This method should be called after the engine notifies the host that the module is ready.
  361. /// This method only needs to be called on root modules - it will execute all of the dependent modules.
  362. ///
  363. /// One moduleRecord will be executed only once. Additional execution call on the same moduleRecord will fail.
  364. /// </remarks>
  365. /// <param name="requestModule">The ModuleRecord being executed.</param>
  366. /// <param name="result">The return value of the module.</param>
  367. /// <returns>
  368. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  369. /// </returns>
  370. CHAKRA_API
  371. JsModuleEvaluation(
  372. _In_ JsModuleRecord requestModule,
  373. _Outptr_result_maybenull_ JsValueRef* result);
  374. /// <summary>
  375. /// Set host info for the specified module.
  376. /// </summary>
  377. /// <remarks>
  378. /// This is used for four things:
  379. /// 1. Setting up the callbacks for module loading - note these are actually
  380. /// set on the module's Context not the module itself so only have to be set
  381. /// for the first root module in any given context.
  382. /// Alternatively you can set these on the currentContext by supplying a nullptr
  383. /// as the requestModule
  384. /// 2. Setting host defined info on a module record - can be anything that
  385. /// you wish to associate with your modules.
  386. /// 3. Setting a URL for a module to be used for stack traces/debugging -
  387. /// note this must be set before calling JsParseModuleSource on the module
  388. /// or it will be ignored.
  389. /// 4. Setting an exception on the module object - only relevant prior to it being Parsed.
  390. /// </remarks>
  391. /// <param name="requestModule">The request module, optional for setting callbacks, required for other uses.</param>
  392. /// <param name="moduleHostInfo">The type of host info to be set.</param>
  393. /// <param name="hostInfo">The host info to be set.</param>
  394. /// <returns>
  395. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  396. /// </returns>
  397. CHAKRA_API
  398. JsSetModuleHostInfo(
  399. _In_opt_ JsModuleRecord requestModule,
  400. _In_ JsModuleHostInfoKind moduleHostInfo,
  401. _In_ void* hostInfo);
  402. /// <summary>
  403. /// Retrieve the host info for the specified module.
  404. /// </summary>
  405. /// <remarks>
  406. /// This can used to retrieve info previously set with JsSetModuleHostInfo.
  407. /// </remarks>
  408. /// <param name="requestModule">The request module.</param>
  409. /// <param name="moduleHostInfo">The type of host info to be retrieved.</param>
  410. /// <param name="hostInfo">The retrieved host info for the module.</param>
  411. /// <returns>
  412. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  413. /// </returns>
  414. CHAKRA_API
  415. JsGetModuleHostInfo(
  416. _In_ JsModuleRecord requestModule,
  417. _In_ JsModuleHostInfoKind moduleHostInfo,
  418. _Outptr_result_maybenull_ void** hostInfo);
  419. /// <summary>
  420. /// Returns metadata relating to the exception that caused the runtime of the current context
  421. /// to be in the exception state and resets the exception state for that runtime. The metadata
  422. /// includes a reference to the exception itself.
  423. /// </summary>
  424. /// <remarks>
  425. /// <para>
  426. /// If the runtime of the current context is not in an exception state, this API will return
  427. /// <c>JsErrorInvalidArgument</c>. If the runtime is disabled, this will return an exception
  428. /// indicating that the script was terminated, but it will not clear the exception (the
  429. /// exception will be cleared if the runtime is re-enabled using
  430. /// <c>JsEnableRuntimeExecution</c>).
  431. /// </para>
  432. /// <para>
  433. /// The metadata value is a javascript object with the following properties: <c>exception</c>, the
  434. /// thrown exception object; <c>line</c>, the 0 indexed line number where the exception was thrown;
  435. /// <c>column</c>, the 0 indexed column number where the exception was thrown; <c>length</c>, the
  436. /// source-length of the cause of the exception; <c>source</c>, a string containing the line of
  437. /// source code where the exception was thrown; and <c>url</c>, a string containing the name of
  438. /// the script file containing the code that threw the exception.
  439. /// </para>
  440. /// <para>
  441. /// Requires an active script context.
  442. /// </para>
  443. /// </remarks>
  444. /// <param name="metadata">The exception metadata for the runtime of the current context.</param>
  445. /// <returns>
  446. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  447. /// </returns>
  448. CHAKRA_API
  449. JsGetAndClearExceptionWithMetadata(
  450. _Out_ JsValueRef *metadata);
  451. /// <summary>
  452. /// Called by the runtime to load the source code of the serialized script.
  453. /// </summary>
  454. /// <param name="sourceContext">The context passed to Js[Parse|Run]SerializedScriptCallback</param>
  455. /// <param name="script">The script returned.</param>
  456. /// <returns>
  457. /// true if the operation succeeded, false otherwise.
  458. /// </returns>
  459. typedef bool (CHAKRA_CALLBACK * JsSerializedLoadScriptCallback)
  460. (JsSourceContext sourceContext, _Out_ JsValueRef *value,
  461. _Out_ JsParseScriptAttributes *parseAttributes);
  462. /// <summary>
  463. /// Create JavascriptString variable from ASCII or Utf8 string
  464. /// </summary>
  465. /// <remarks>
  466. /// <para>
  467. /// Requires an active script context.
  468. /// </para>
  469. /// <para>
  470. /// Input string can be either ASCII or Utf8
  471. /// </para>
  472. /// </remarks>
  473. /// <param name="content">Pointer to string memory.</param>
  474. /// <param name="length">Number of bytes within the string</param>
  475. /// <param name="value">JsValueRef representing the JavascriptString</param>
  476. /// <returns>
  477. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  478. /// </returns>
  479. CHAKRA_API
  480. JsCreateString(
  481. _In_ const char *content,
  482. _In_ size_t length,
  483. _Out_ JsValueRef *value);
  484. /// <summary>
  485. /// Create JavascriptString variable from Utf16 string
  486. /// </summary>
  487. /// <remarks>
  488. /// <para>
  489. /// Requires an active script context.
  490. /// </para>
  491. /// <para>
  492. /// Expects Utf16 string
  493. /// </para>
  494. /// </remarks>
  495. /// <param name="content">Pointer to string memory.</param>
  496. /// <param name="length">Number of characters within the string</param>
  497. /// <param name="value">JsValueRef representing the JavascriptString</param>
  498. /// <returns>
  499. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  500. /// </returns>
  501. CHAKRA_API
  502. JsCreateStringUtf16(
  503. _In_ const uint16_t *content,
  504. _In_ size_t length,
  505. _Out_ JsValueRef *value);
  506. /// <summary>
  507. /// Write JavascriptString value into C string buffer (Utf8)
  508. /// </summary>
  509. /// <remarks>
  510. /// <para>
  511. /// When size of the `buffer` is unknown,
  512. /// `buffer` argument can be nullptr.
  513. /// In that case, `length` argument will return the length needed.
  514. /// </para>
  515. /// </remarks>
  516. /// <param name="value">JavascriptString value</param>
  517. /// <param name="buffer">Pointer to buffer</param>
  518. /// <param name="bufferSize">Buffer size</param>
  519. /// <param name="length">Total number of characters needed or written</param>
  520. /// <returns>
  521. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  522. /// </returns>
  523. CHAKRA_API
  524. JsCopyString(
  525. _In_ JsValueRef value,
  526. _Out_opt_ char* buffer,
  527. _In_ size_t bufferSize,
  528. _Out_opt_ size_t* length);
  529. /// <summary>
  530. /// Write string value into Utf16 string buffer
  531. /// </summary>
  532. /// <remarks>
  533. /// <para>
  534. /// When size of the `buffer` is unknown,
  535. /// `buffer` argument can be nullptr.
  536. /// In that case, `written` argument will return the length needed.
  537. /// </para>
  538. /// <para>
  539. /// when start is out of range or &lt; 0, returns JsErrorInvalidArgument
  540. /// and `written` will be equal to 0.
  541. /// If calculated length is 0 (It can be due to string length or `start`
  542. /// and length combination), then `written` will be equal to 0 and call
  543. /// returns JsNoError
  544. /// </para>
  545. /// </remarks>
  546. /// <param name="value">JavascriptString value</param>
  547. /// <param name="start">start offset of buffer</param>
  548. /// <param name="length">length to be written</param>
  549. /// <param name="buffer">Pointer to buffer</param>
  550. /// <param name="written">Total number of characters written</param>
  551. /// <returns>
  552. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  553. /// </returns>
  554. CHAKRA_API
  555. JsCopyStringUtf16(
  556. _In_ JsValueRef value,
  557. _In_ int start,
  558. _In_ int length,
  559. _Out_opt_ uint16_t* buffer,
  560. _Out_opt_ size_t* written);
  561. /// <summary>
  562. /// Parses a script and returns a function representing the script.
  563. /// </summary>
  564. /// <remarks>
  565. /// <para>
  566. /// Requires an active script context.
  567. /// </para>
  568. /// <para>
  569. /// Script source can be either JavascriptString or JavascriptExternalArrayBuffer.
  570. /// In case it is an ExternalArrayBuffer, and the encoding of the buffer is Utf16,
  571. /// JsParseScriptAttributeArrayBufferIsUtf16Encoded is expected on parseAttributes.
  572. /// </para>
  573. /// <para>
  574. /// Use JavascriptExternalArrayBuffer with Utf8/ASCII script source
  575. /// for better performance and smaller memory footprint.
  576. /// </para>
  577. /// </remarks>
  578. /// <param name="script">The script to run.</param>
  579. /// <param name="sourceContext">
  580. /// A cookie identifying the script that can be used by debuggable script contexts.
  581. /// </param>
  582. /// <param name="sourceUrl">The location the script came from.</param>
  583. /// <param name="parseAttributes">Attribute mask for parsing the script</param>
  584. /// <param name="result">The result of the compiled script.</param>
  585. /// <returns>
  586. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  587. /// </returns>
  588. CHAKRA_API
  589. JsParse(
  590. _In_ JsValueRef script,
  591. _In_ JsSourceContext sourceContext,
  592. _In_ JsValueRef sourceUrl,
  593. _In_ JsParseScriptAttributes parseAttributes,
  594. _Out_ JsValueRef *result);
  595. /// <summary>
  596. /// Executes a script.
  597. /// </summary>
  598. /// <remarks>
  599. /// <para>
  600. /// Requires an active script context.
  601. /// </para>
  602. /// <para>
  603. /// Script source can be either JavascriptString or JavascriptExternalArrayBuffer.
  604. /// In case it is an ExternalArrayBuffer, and the encoding of the buffer is Utf16,
  605. /// JsParseScriptAttributeArrayBufferIsUtf16Encoded is expected on parseAttributes.
  606. /// </para>
  607. /// <para>
  608. /// Use JavascriptExternalArrayBuffer with Utf8/ASCII script source
  609. /// for better performance and smaller memory footprint.
  610. /// </para>
  611. /// </remarks>
  612. /// <param name="script">The script to run.</param>
  613. /// <param name="sourceContext">
  614. /// A cookie identifying the script that can be used by debuggable script contexts.
  615. /// </param>
  616. /// <param name="sourceUrl">The location the script came from</param>
  617. /// <param name="parseAttributes">Attribute mask for parsing the script</param>
  618. /// <param name="result">The result of the script, if any. This parameter can be null.</param>
  619. /// <returns>
  620. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  621. /// </returns>
  622. CHAKRA_API
  623. JsRun(
  624. _In_ JsValueRef script,
  625. _In_ JsSourceContext sourceContext,
  626. _In_ JsValueRef sourceUrl,
  627. _In_ JsParseScriptAttributes parseAttributes,
  628. _Out_ JsValueRef *result);
  629. /// <summary>
  630. /// Creates the property ID associated with the name.
  631. /// </summary>
  632. /// <remarks>
  633. /// <para>
  634. /// Property IDs are specific to a context and cannot be used across contexts.
  635. /// </para>
  636. /// <para>
  637. /// Requires an active script context.
  638. /// </para>
  639. /// </remarks>
  640. /// <param name="name">
  641. /// The name of the property ID to get or create. The string is expected to be ASCII / utf8 encoded.
  642. /// The name can be any JavaScript property identifier, including all digits.
  643. /// </param>
  644. /// <param name="length">length of the name in bytes</param>
  645. /// <param name="propertyId">The property ID in this runtime for the given name.</param>
  646. /// <returns>
  647. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  648. /// </returns>
  649. CHAKRA_API
  650. JsCreatePropertyId(
  651. _In_z_ const char *name,
  652. _In_ size_t length,
  653. _Out_ JsPropertyIdRef *propertyId);
  654. /// <summary>
  655. /// Creates the property ID associated with the name.
  656. /// </summary>
  657. /// <remarks>
  658. /// <para>
  659. /// Property IDs are specific to a context and cannot be used across contexts.
  660. /// </para>
  661. /// <para>
  662. /// Requires an active script context.
  663. /// </para>
  664. /// </remarks>
  665. /// <param name="name">
  666. /// The name of the property ID to get or create. The name may consist of only digits.
  667. /// The string is expected to be ASCII / utf8 encoded.
  668. /// </param>
  669. /// <param name="length">length of the name in bytes</param>
  670. /// <param name="propertyString">The property string in this runtime for the given name.</param>
  671. /// <returns>
  672. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  673. /// </returns>
  674. CHAKRA_API
  675. JsCreatePropertyString(
  676. _In_z_ const char *name,
  677. _In_ size_t length,
  678. _Out_ JsValueRef* propertyString);
  679. /// <summary>
  680. /// Copies the name associated with the property ID into a buffer.
  681. /// </summary>
  682. /// <remarks>
  683. /// <para>
  684. /// Requires an active script context.
  685. /// </para>
  686. /// <para>
  687. /// When size of the `buffer` is unknown,
  688. /// `buffer` argument can be nullptr.
  689. /// `length` argument will return the size needed.
  690. /// </para>
  691. /// </remarks>
  692. /// <param name="propertyId">The property ID to get the name of.</param>
  693. /// <param name="buffer">The buffer holding the name associated with the property ID, encoded as utf8</param>
  694. /// <param name="bufferSize">Size of the buffer.</param>
  695. /// <param name="written">Total number of characters written or to be written</param>
  696. /// <returns>
  697. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  698. /// </returns>
  699. CHAKRA_API
  700. JsCopyPropertyId(
  701. _In_ JsPropertyIdRef propertyId,
  702. _Out_ char* buffer,
  703. _In_ size_t bufferSize,
  704. _Out_ size_t* length);
  705. /// <summary>
  706. /// Serializes a parsed script to a buffer than can be reused.
  707. /// </summary>
  708. /// <remarks>
  709. /// <para>
  710. /// <c>JsSerializeScript</c> parses a script and then stores the parsed form of the script in a
  711. /// runtime-independent format. The serialized script then can be deserialized in any
  712. /// runtime without requiring the script to be re-parsed.
  713. /// </para>
  714. /// <para>
  715. /// Requires an active script context.
  716. /// </para>
  717. /// <para>
  718. /// Script source can be either JavascriptString or JavascriptExternalArrayBuffer.
  719. /// In case it is an ExternalArrayBuffer, and the encoding of the buffer is Utf16,
  720. /// JsParseScriptAttributeArrayBufferIsUtf16Encoded is expected on parseAttributes.
  721. /// </para>
  722. /// <para>
  723. /// Use JavascriptExternalArrayBuffer with Utf8/ASCII script source
  724. /// for better performance and smaller memory footprint.
  725. /// </para>
  726. /// </remarks>
  727. /// <param name="script">The script to serialize</param>
  728. /// <param name="buffer">ArrayBuffer</param>
  729. /// <param name="parseAttributes">Encoding for the script.</param>
  730. /// <returns>
  731. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  732. /// </returns>
  733. CHAKRA_API
  734. JsSerialize(
  735. _In_ JsValueRef script,
  736. _Out_ JsValueRef *buffer,
  737. _In_ JsParseScriptAttributes parseAttributes);
  738. /// <summary>
  739. /// Parses a serialized script and returns a function representing the script.
  740. /// Provides the ability to lazy load the script source only if/when it is needed.
  741. /// </summary>
  742. /// <remarks>
  743. /// <para>
  744. /// Requires an active script context.
  745. /// </para>
  746. /// </remarks>
  747. /// <param name="buffer">The serialized script as an ArrayBuffer (preferably ExternalArrayBuffer).</param>
  748. /// <param name="scriptLoadCallback">
  749. /// Callback called when the source code of the script needs to be loaded.
  750. /// This is an optional parameter, set to null if not needed.
  751. /// </param>
  752. /// <param name="sourceContext">
  753. /// A cookie identifying the script that can be used by debuggable script contexts.
  754. /// This context will passed into scriptLoadCallback.
  755. /// </param>
  756. /// <param name="sourceUrl">The location the script came from.</param>
  757. /// <param name="result">A function representing the script code.</param>
  758. /// <returns>
  759. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  760. /// </returns>
  761. CHAKRA_API
  762. JsParseSerialized(
  763. _In_ JsValueRef buffer,
  764. _In_ JsSerializedLoadScriptCallback scriptLoadCallback,
  765. _In_ JsSourceContext sourceContext,
  766. _In_ JsValueRef sourceUrl,
  767. _Out_ JsValueRef *result);
  768. /// <summary>
  769. /// Runs a serialized script.
  770. /// Provides the ability to lazy load the script source only if/when it is needed.
  771. /// </summary>
  772. /// <remarks>
  773. /// <para>
  774. /// Requires an active script context.
  775. /// </para>
  776. /// <para>
  777. /// The runtime will detach the data from the buffer and hold on to it until all
  778. /// instances of any functions created from the buffer are garbage collected.
  779. /// </para>
  780. /// </remarks>
  781. /// <param name="buffer">The serialized script as an ArrayBuffer (preferably ExternalArrayBuffer).</param>
  782. /// <param name="scriptLoadCallback">Callback called when the source code of the script needs to be loaded.</param>
  783. /// <param name="sourceContext">
  784. /// A cookie identifying the script that can be used by debuggable script contexts.
  785. /// This context will passed into scriptLoadCallback.
  786. /// </param>
  787. /// <param name="sourceUrl">The location the script came from.</param>
  788. /// <param name="result">
  789. /// The result of running the script, if any. This parameter can be null.
  790. /// </param>
  791. /// <returns>
  792. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  793. /// </returns>
  794. CHAKRA_API
  795. JsRunSerialized(
  796. _In_ JsValueRef buffer,
  797. _In_ JsSerializedLoadScriptCallback scriptLoadCallback,
  798. _In_ JsSourceContext sourceContext,
  799. _In_ JsValueRef sourceUrl,
  800. _Out_ JsValueRef *result);
  801. /// <summary>
  802. /// Gets the state of a given Promise object.
  803. /// </summary>
  804. /// <remarks>
  805. /// Requires an active script context.
  806. /// </remarks>
  807. /// <param name="promise">The Promise object.</param>
  808. /// <param name="state">The current state of the Promise.</param>
  809. /// <returns>
  810. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  811. /// </returns>
  812. CHAKRA_API
  813. JsGetPromiseState(
  814. _In_ JsValueRef promise,
  815. _Out_ JsPromiseState *state);
  816. /// <summary>
  817. /// Gets the result of a given Promise object.
  818. /// </summary>
  819. /// <remarks>
  820. /// Requires an active script context.
  821. /// </remarks>
  822. /// <param name="promise">The Promise object.</param>
  823. /// <param name="result">The result of the Promise.</param>
  824. /// <returns>
  825. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  826. /// </returns>
  827. CHAKRA_API
  828. JsGetPromiseResult(
  829. _In_ JsValueRef promise,
  830. _Out_ JsValueRef *result);
  831. /// <summary>
  832. /// Creates a new JavaScript Promise object.
  833. /// </summary>
  834. /// <remarks>
  835. /// Requires an active script context.
  836. /// </remarks>
  837. /// <param name="promise">The new Promise object.</param>
  838. /// <param name="resolveFunction">The function called to resolve the created Promise object.</param>
  839. /// <param name="rejectFunction">The function called to reject the created Promise object.</param>
  840. /// <returns>
  841. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  842. /// </returns>
  843. CHAKRA_API
  844. JsCreatePromise(
  845. _Out_ JsValueRef *promise,
  846. _Out_ JsValueRef *resolveFunction,
  847. _Out_ JsValueRef *rejectFunction);
  848. /// <summary>
  849. /// A weak reference to a JavaScript value.
  850. /// </summary>
  851. /// <remarks>
  852. /// A value with only weak references is available for garbage-collection. A strong reference
  853. /// to the value (<c>JsValueRef</c>) may be obtained from a weak reference if the value happens
  854. /// to still be available.
  855. /// </remarks>
  856. typedef JsRef JsWeakRef;
  857. /// <summary>
  858. /// Creates a weak reference to a value.
  859. /// </summary>
  860. /// <param name="value">The value to be referenced.</param>
  861. /// <param name="weakRef">Weak reference to the value.</param>
  862. /// <returns>
  863. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  864. /// </returns>
  865. CHAKRA_API
  866. JsCreateWeakReference(
  867. _In_ JsValueRef value,
  868. _Out_ JsWeakRef* weakRef);
  869. /// <summary>
  870. /// Gets a strong reference to the value referred to by a weak reference.
  871. /// </summary>
  872. /// <param name="weakRef">A weak reference.</param>
  873. /// <param name="value">Reference to the value, or <c>JS_INVALID_REFERENCE</c> if the value is
  874. /// no longer available.</param>
  875. /// <returns>
  876. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  877. /// </returns>
  878. CHAKRA_API
  879. JsGetWeakReferenceValue(
  880. _In_ JsWeakRef weakRef,
  881. _Out_ JsValueRef* value);
  882. /// <summary>
  883. /// Creates a Javascript SharedArrayBuffer object with shared content get from JsGetSharedArrayBufferContent.
  884. /// </summary>
  885. /// <remarks>
  886. /// Requires an active script context.
  887. /// </remarks>
  888. /// <param name="sharedContents">
  889. /// The storage object of a SharedArrayBuffer which can be shared between multiple thread.
  890. /// </param>
  891. /// <param name="result">The new SharedArrayBuffer object.</param>
  892. /// <returns>
  893. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  894. /// </returns>
  895. CHAKRA_API
  896. JsCreateSharedArrayBufferWithSharedContent(
  897. _In_ JsSharedArrayBufferContentHandle sharedContents,
  898. _Out_ JsValueRef *result);
  899. /// <summary>
  900. /// Get the storage object from a SharedArrayBuffer.
  901. /// </summary>
  902. /// <remarks>
  903. /// Requires an active script context.
  904. /// </remarks>
  905. /// <param name="sharedArrayBuffer">The SharedArrayBuffer object.</param>
  906. /// <param name="sharedContents">
  907. /// The storage object of a SharedArrayBuffer which can be shared between multiple thread.
  908. /// User should call JsReleaseSharedArrayBufferContentHandle after finished using it.
  909. /// </param>
  910. /// <returns>
  911. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  912. /// </returns>
  913. CHAKRA_API
  914. JsGetSharedArrayBufferContent(
  915. _In_ JsValueRef sharedArrayBuffer,
  916. _Out_ JsSharedArrayBufferContentHandle *sharedContents);
  917. /// <summary>
  918. /// Decrease the reference count on a SharedArrayBuffer storage object.
  919. /// </summary>
  920. /// <remarks>
  921. /// Requires an active script context.
  922. /// </remarks>
  923. /// <param name="sharedContents">
  924. /// The storage object of a SharedArrayBuffer which can be shared between multiple thread.
  925. /// </param>
  926. /// <returns>
  927. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  928. /// </returns>
  929. CHAKRA_API
  930. JsReleaseSharedArrayBufferContentHandle(
  931. _In_ JsSharedArrayBufferContentHandle sharedContents);
  932. /// <summary>
  933. /// Determines whether an object has a non-inherited property.
  934. /// </summary>
  935. /// <remarks>
  936. /// Requires an active script context.
  937. /// </remarks>
  938. /// <param name="object">The object that may contain the property.</param>
  939. /// <param name="propertyId">The ID of the property.</param>
  940. /// <param name="hasOwnProperty">Whether the object has the non-inherited property.</param>
  941. /// <returns>
  942. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  943. /// </returns>
  944. CHAKRA_API
  945. JsHasOwnProperty(
  946. _In_ JsValueRef object,
  947. _In_ JsPropertyIdRef propertyId,
  948. _Out_ bool *hasOwnProperty);
  949. /// <summary>
  950. /// Determines whether an object has a non-inherited property.
  951. /// </summary>
  952. /// <remarks>
  953. /// Requires an active script context.
  954. /// </remarks>
  955. /// <param name="object">The object that may contain the item.</param>
  956. /// <param name="index">The index to find.</param>
  957. /// <param name="hasOwnProperty">Whether the object has the non-inherited
  958. /// property.</param> <returns>
  959. /// The code <c>JsNoError</c> if the operation succeeded, a failure code
  960. /// otherwise.
  961. /// </returns>
  962. CHAKRA_API
  963. JsHasOwnItem(
  964. _In_ JsValueRef object,
  965. _In_ uint32_t index,
  966. _Out_ bool* hasOwnItem);
  967. /// <summary>
  968. /// Write JS string value into char string buffer without a null terminator
  969. /// </summary>
  970. /// <remarks>
  971. /// <para>
  972. /// When size of the `buffer` is unknown,
  973. /// `buffer` argument can be nullptr.
  974. /// In that case, `written` argument will return the length needed.
  975. /// </para>
  976. /// <para>
  977. /// When start is out of range or &lt; 0, returns JsErrorInvalidArgument
  978. /// and `written` will be equal to 0.
  979. /// If calculated length is 0 (It can be due to string length or `start`
  980. /// and length combination), then `written` will be equal to 0 and call
  981. /// returns JsNoError
  982. /// </para>
  983. /// <para>
  984. /// The JS string `value` will be converted one utf16 code point at a time,
  985. /// and if it has code points that do not fit in one byte, those values
  986. /// will be truncated.
  987. /// </para>
  988. /// </remarks>
  989. /// <param name="value">JavascriptString value</param>
  990. /// <param name="start">Start offset of buffer</param>
  991. /// <param name="length">Number of characters to be written</param>
  992. /// <param name="buffer">Pointer to buffer</param>
  993. /// <param name="written">Total number of characters written</param>
  994. /// <returns>
  995. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  996. /// </returns>
  997. CHAKRA_API
  998. JsCopyStringOneByte(
  999. _In_ JsValueRef value,
  1000. _In_ int start,
  1001. _In_ int length,
  1002. _Out_opt_ char* buffer,
  1003. _Out_opt_ size_t* written);
  1004. /// <summary>
  1005. /// Obtains frequently used properties of a data view.
  1006. /// </summary>
  1007. /// <param name="dataView">The data view instance.</param>
  1008. /// <param name="arrayBuffer">The ArrayBuffer backstore of the view.</param>
  1009. /// <param name="byteOffset">The offset in bytes from the start of arrayBuffer referenced by the array.</param>
  1010. /// <param name="byteLength">The number of bytes in the array.</param>
  1011. /// <returns>
  1012. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1013. /// </returns>
  1014. CHAKRA_API
  1015. JsGetDataViewInfo(
  1016. _In_ JsValueRef dataView,
  1017. _Out_opt_ JsValueRef *arrayBuffer,
  1018. _Out_opt_ unsigned int *byteOffset,
  1019. _Out_opt_ unsigned int *byteLength);
  1020. /// <summary>
  1021. /// Determine if one JavaScript value is less than another JavaScript value.
  1022. /// </summary>
  1023. /// <remarks>
  1024. /// <para>
  1025. /// This function is equivalent to the <c>&lt;</c> operator in Javascript.
  1026. /// </para>
  1027. /// <para>
  1028. /// Requires an active script context.
  1029. /// </para>
  1030. /// </remarks>
  1031. /// <param name="object1">The first object to compare.</param>
  1032. /// <param name="object2">The second object to compare.</param>
  1033. /// <param name="result">Whether object1 is less than object2.</param>
  1034. /// <returns>
  1035. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1036. /// </returns>
  1037. CHAKRA_API
  1038. JsLessThan(
  1039. _In_ JsValueRef object1,
  1040. _In_ JsValueRef object2,
  1041. _Out_ bool *result);
  1042. /// <summary>
  1043. /// Determine if one JavaScript value is less than or equal to another JavaScript value.
  1044. /// </summary>
  1045. /// <remarks>
  1046. /// <para>
  1047. /// This function is equivalent to the <c>&lt;=</c> operator in Javascript.
  1048. /// </para>
  1049. /// <para>
  1050. /// Requires an active script context.
  1051. /// </para>
  1052. /// </remarks>
  1053. /// <param name="object1">The first object to compare.</param>
  1054. /// <param name="object2">The second object to compare.</param>
  1055. /// <param name="result">Whether object1 is less than or equal to object2.</param>
  1056. /// <returns>
  1057. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1058. /// </returns>
  1059. CHAKRA_API
  1060. JsLessThanOrEqual(
  1061. _In_ JsValueRef object1,
  1062. _In_ JsValueRef object2,
  1063. _Out_ bool *result);
  1064. /// <summary>
  1065. /// Creates a new object (with prototype) that stores some external data.
  1066. /// </summary>
  1067. /// <remarks>
  1068. /// Requires an active script context.
  1069. /// </remarks>
  1070. /// <param name="data">External data that the object will represent. May be null.</param>
  1071. /// <param name="finalizeCallback">
  1072. /// A callback for when the object is finalized. May be null.
  1073. /// </param>
  1074. /// <param name="prototype">Prototype object or nullptr.</param>
  1075. /// <param name="object">The new object.</param>
  1076. /// <returns>
  1077. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1078. /// </returns>
  1079. CHAKRA_API
  1080. JsCreateExternalObjectWithPrototype(
  1081. _In_opt_ void *data,
  1082. _In_opt_ JsFinalizeCallback finalizeCallback,
  1083. _In_opt_ JsValueRef prototype,
  1084. _Out_ JsValueRef *object);
  1085. /// <summary>
  1086. /// Creates a new object (with prototype) that stores some data.
  1087. /// </summary>
  1088. /// <remarks>
  1089. /// Requires an active script context.
  1090. /// </remarks>
  1091. /// <param name="data">External data that the object will represent. May be null.</param>
  1092. /// <param name="traceCallback">
  1093. /// A callback for when the object is traced. May be null.
  1094. /// <param name="finalizeCallback">
  1095. /// A callback for when the object is finalized. May be null.
  1096. /// </param>
  1097. /// <param name="prototype">Prototype object or nullptr.</param>
  1098. /// <param name="object">The new object.</param>
  1099. /// <returns>
  1100. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1101. /// </returns>
  1102. CHAKRA_API
  1103. JsCreateTracedExternalObject(
  1104. _In_opt_ void *data,
  1105. _In_opt_ size_t inlineSlotSize,
  1106. _In_opt_ JsTraceCallback traceCallback,
  1107. _In_opt_ JsFinalizeCallback finalizeCallback,
  1108. _In_opt_ JsValueRef prototype,
  1109. _Out_ JsValueRef *object);
  1110. /// <summary>
  1111. /// Creates a new object (with prototype) that stores some external data and also supports interceptors.
  1112. /// </summary>
  1113. /// <remarks>
  1114. /// Requires an active script context.
  1115. /// </remarks>
  1116. /// <param name="data">External data that the object will represent. May be null.</param>
  1117. /// <param name="finalizeCallback">
  1118. /// A callback for when the object is finalized. May be null.
  1119. /// </param>
  1120. /// <param name="prototype">Prototype object or nullptr.</param>
  1121. /// <param name="object">The new object.</param>
  1122. /// <returns>
  1123. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1124. /// </returns>
  1125. CHAKRA_API
  1126. JsCreateCustomExternalObject(
  1127. _In_opt_ void *data,
  1128. _In_opt_ size_t inlineSlotSize,
  1129. _In_opt_ JsTraceCallback traceCallback,
  1130. _In_opt_ JsFinalizeCallback finalizeCallback,
  1131. _Inout_opt_ JsGetterSetterInterceptor ** getterSetterInterceptor,
  1132. _In_opt_ JsValueRef prototype,
  1133. _Out_ JsValueRef * object);
  1134. /// <summary>
  1135. /// Returns a reference to the Array.Prototype.forEach function. The function is created if it's not already present.
  1136. /// </summary>
  1137. /// <param name="result">A reference to the Array.Prototype.forEach function.</param>
  1138. CHAKRA_API
  1139. JsGetArrayForEachFunction(_Out_ JsValueRef * result);
  1140. /// <summary>
  1141. /// Returns a reference to the Array.Prototype.keys function. The function is created if it's not already present.
  1142. /// </summary>
  1143. /// <param name="result">A reference to the Array.Prototype.keys function.</param>
  1144. CHAKRA_API
  1145. JsGetArrayKeysFunction(_Out_ JsValueRef * result);
  1146. /// <summary>
  1147. /// Returns a reference to the Array.Prototype.values function. The function is created if it's not already present.
  1148. /// </summary>
  1149. /// <param name="result">A reference to the Array.Prototype.values function.</param>
  1150. CHAKRA_API
  1151. JsGetArrayValuesFunction(_Out_ JsValueRef * result);
  1152. /// <summary>
  1153. /// Returns a reference to the Array.Prototype.entries function. The function is created if it's not already present.
  1154. /// </summary>
  1155. /// <param name="result">A reference to the Array.Prototype.entries function.</param>
  1156. CHAKRA_API
  1157. JsGetArrayEntriesFunction(_Out_ JsValueRef * result);
  1158. /// <summary>
  1159. /// Returns the property id of the Symbol.iterator property.
  1160. /// </summary>
  1161. /// <param name="propertyId">The property id of the Symbol.iterator property.</param>
  1162. CHAKRA_API
  1163. JsGetPropertyIdSymbolIterator(_Out_ JsPropertyIdRef * propertyId);
  1164. /// <summary>
  1165. /// Returns a reference to the Javascript error prototype object.
  1166. /// </summary>
  1167. /// <param name="result">A reference to the Javascript error prototype object.</param>
  1168. CHAKRA_API
  1169. JsGetErrorPrototype(_Out_ JsValueRef * result);
  1170. /// <summary>
  1171. /// Returns a reference to the Javascript iterator prototype object.
  1172. /// </summary>
  1173. /// <param name="result">A reference to the Javascript iterator prototype object.</param>
  1174. CHAKRA_API
  1175. JsGetIteratorPrototype(_Out_ JsValueRef * result);
  1176. /// <summary>
  1177. /// Returns a value that indicates whether an object is callable.
  1178. /// </summary>
  1179. /// <remarks>
  1180. /// Requires an active script context.
  1181. /// </remarks>
  1182. /// <param name="object">The object to test.</param>
  1183. /// <param name="isConstructor">If the object is callable, <c>true</c>, <c>false</c> otherwise.</param>
  1184. /// <returns>
  1185. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1186. /// </returns>
  1187. CHAKRA_API
  1188. JsIsCallable(
  1189. _In_ JsValueRef object,
  1190. _Out_ bool *isCallable);
  1191. /// <summary>
  1192. /// Returns a value that indicates whether an object is a constructor.
  1193. /// </summary>
  1194. /// <remarks>
  1195. /// Requires an active script context.
  1196. /// </remarks>
  1197. /// <param name="object">The object to test.</param>
  1198. /// <param name="isConstructor">If the object is a constructor, <c>true</c>, <c>false</c> otherwise.</param>
  1199. /// <returns>
  1200. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1201. /// </returns>
  1202. CHAKRA_API
  1203. JsIsConstructor(
  1204. _In_ JsValueRef object,
  1205. _Out_ bool *isConstructor);
  1206. /// <summary>
  1207. /// Clones an object
  1208. /// </summary>
  1209. /// <param name="source">The original object.</param>
  1210. /// <param name="clonedObject">
  1211. /// Pointer to the cloned object.
  1212. /// </param>
  1213. /// <returns>
  1214. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1215. /// </returns>
  1216. CHAKRA_API
  1217. JsCloneObject(
  1218. _In_ JsValueRef source,
  1219. _Out_ JsValueRef* clonedObject);
  1220. /// <summary>
  1221. /// Determines whether an object has a private property.
  1222. /// </summary>
  1223. /// <remarks>
  1224. /// Requires an active script context.
  1225. /// </remarks>
  1226. /// <param name="object">The object that may contain the property.</param>
  1227. /// <param name="key">The key (JavascriptString or JavascriptSymbol) to the property.</param>
  1228. /// <param name="hasProperty">Whether the object (or a prototype) has the property.</param>
  1229. /// <returns>
  1230. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1231. /// </returns>
  1232. CHAKRA_API
  1233. JsPrivateHasProperty(
  1234. _In_ JsValueRef object,
  1235. _In_ JsValueRef key,
  1236. _Out_ bool *hasProperty);
  1237. /// <summary>
  1238. /// Gets an object's private property
  1239. /// </summary>
  1240. /// <remarks>
  1241. /// Requires an active script context.
  1242. /// </remarks>
  1243. /// <param name="object">The object that contains the property.</param>
  1244. /// <param name="key">The key (JavascriptString or JavascriptSymbol) to the property.</param>
  1245. /// <param name="value">The value of the property.</param>
  1246. /// <returns>
  1247. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1248. /// </returns>
  1249. CHAKRA_API
  1250. JsPrivateGetProperty(
  1251. _In_ JsValueRef object,
  1252. _In_ JsValueRef key,
  1253. _Out_ JsValueRef *value);
  1254. /// <summary>
  1255. /// Puts an object's private property.
  1256. /// </summary>
  1257. /// <remarks>
  1258. /// Requires an active script context.
  1259. /// </remarks>
  1260. /// <param name="object">The object that contains the property.</param>
  1261. /// <param name="key">The key (JavascriptString or JavascriptSymbol) to the property.</param>
  1262. /// <param name="value">The new value of the property.</param>
  1263. /// <returns>
  1264. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1265. /// </returns>
  1266. CHAKRA_API
  1267. JsPrivateSetProperty(
  1268. _In_ JsValueRef object,
  1269. _In_ JsValueRef key,
  1270. _In_ JsValueRef value);
  1271. /// <summary>
  1272. /// Deletes an object's private property.
  1273. /// </summary>
  1274. /// <remarks>
  1275. /// Requires an active script context.
  1276. /// </remarks>
  1277. /// <param name="object">The object that contains the property.</param>
  1278. /// <param name="key">The key (JavascriptString or JavascriptSymbol) to the property.</param>
  1279. /// <param name="result">Whether the property was deleted.</param>
  1280. /// <returns>
  1281. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1282. /// </returns>
  1283. CHAKRA_API
  1284. JsPrivateDeleteProperty(
  1285. _In_ JsValueRef object,
  1286. _In_ JsValueRef key,
  1287. _Out_ JsValueRef *result);
  1288. /// <summary>
  1289. /// Gets an object's property.
  1290. /// </summary>
  1291. /// <remarks>
  1292. /// Requires an active script context.
  1293. /// </remarks>
  1294. /// <param name="object">The object that contains the property.</param>
  1295. /// <param name="key">The key (JavascriptString or JavascriptSymbol) to the property.</param>
  1296. /// <param name="value">The value of the property.</param>
  1297. /// <returns>
  1298. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1299. /// </returns>
  1300. CHAKRA_API
  1301. JsObjectGetProperty(
  1302. _In_ JsValueRef object,
  1303. _In_ JsValueRef key,
  1304. _Out_ JsValueRef *value);
  1305. /// <summary>
  1306. /// Puts an object's property.
  1307. /// </summary>
  1308. /// <remarks>
  1309. /// Requires an active script context.
  1310. /// </remarks>
  1311. /// <param name="object">The object that contains the property.</param>
  1312. /// <param name="key">The key (JavascriptString or JavascriptSymbol) to the property.</param>
  1313. /// <param name="value">The new value of the property.</param>
  1314. /// <param name="useStrictRules">The property set should follow strict mode rules.</param>
  1315. /// <returns>
  1316. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1317. /// </returns>
  1318. CHAKRA_API
  1319. JsObjectSetProperty(
  1320. _In_ JsValueRef object,
  1321. _In_ JsValueRef key,
  1322. _In_ JsValueRef value,
  1323. _In_ bool useStrictRules);
  1324. /// <summary>
  1325. /// Determines whether an object has a property.
  1326. /// </summary>
  1327. /// <remarks>
  1328. /// Requires an active script context.
  1329. /// </remarks>
  1330. /// <param name="object">The object that may contain the property.</param>
  1331. /// <param name="key">The key (JavascriptString or JavascriptSymbol) to the property.</param>
  1332. /// <param name="hasProperty">Whether the object (or a prototype) has the property.</param>
  1333. /// <returns>
  1334. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1335. /// </returns>
  1336. CHAKRA_API
  1337. JsObjectHasProperty(
  1338. _In_ JsValueRef object,
  1339. _In_ JsValueRef key,
  1340. _Out_ bool *hasProperty);
  1341. /// <summary>
  1342. /// Defines a new object's own property from a property descriptor.
  1343. /// </summary>
  1344. /// <remarks>
  1345. /// Requires an active script context.
  1346. /// </remarks>
  1347. /// <param name="object">The object that has the property.</param>
  1348. /// <param name="key">The key (JavascriptString or JavascriptSymbol) to the property.</param>
  1349. /// <param name="propertyDescriptor">The property descriptor.</param>
  1350. /// <param name="result">Whether the property was defined.</param>
  1351. /// <returns>
  1352. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1353. /// </returns>
  1354. CHAKRA_API
  1355. JsObjectDefineProperty(
  1356. _In_ JsValueRef object,
  1357. _In_ JsValueRef key,
  1358. _In_ JsValueRef propertyDescriptor,
  1359. _Out_ bool *result);
  1360. /// <summary>
  1361. /// Defines a new object's own property from a property descriptor.
  1362. /// </summary>
  1363. /// <remarks>
  1364. /// Requires an active script context.
  1365. /// </remarks>
  1366. /// <param name="object">The object that has the property.</param>
  1367. /// <param name="key">The key (JavascriptString or JavascriptSymbol) to the property.</param>
  1368. /// <param name="propertyDescriptor">The property descriptor.</param>
  1369. /// <param name="result">Whether the property was defined.</param>
  1370. /// <returns>
  1371. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1372. /// </returns>
  1373. CHAKRA_API
  1374. JsObjectDefinePropertyFull(
  1375. _In_ JsValueRef object,
  1376. _In_ JsValueRef key,
  1377. _In_opt_ JsValueRef value,
  1378. _In_opt_ JsValueRef getter,
  1379. _In_opt_ JsValueRef setter,
  1380. _In_ bool writable,
  1381. _In_ bool enumerable,
  1382. _In_ bool configurable,
  1383. _Out_ bool *result);
  1384. /// <summary>
  1385. /// Deletes an object's property.
  1386. /// </summary>
  1387. /// <remarks>
  1388. /// Requires an active script context.
  1389. /// </remarks>
  1390. /// <param name="object">The object that contains the property.</param>
  1391. /// <param name="key">The key (JavascriptString or JavascriptSymbol) to the property.</param>
  1392. /// <param name="useStrictRules">The property set should follow strict mode rules.</param>
  1393. /// <param name="result">Whether the property was deleted.</param>
  1394. /// <returns>
  1395. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1396. /// </returns>
  1397. CHAKRA_API
  1398. JsObjectDeleteProperty(
  1399. _In_ JsValueRef object,
  1400. _In_ JsValueRef key,
  1401. _In_ bool useStrictRules,
  1402. _Out_ JsValueRef *result);
  1403. /// <summary>
  1404. /// Gets a property descriptor for an object's own property.
  1405. /// </summary>
  1406. /// <remarks>
  1407. /// Requires an active script context.
  1408. /// </remarks>
  1409. /// <param name="object">The object that has the property.</param>
  1410. /// <param name="key">The key (JavascriptString or JavascriptSymbol) to the property.</param>
  1411. /// <param name="propertyDescriptor">The property descriptor.</param>
  1412. /// <returns>
  1413. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1414. /// </returns>
  1415. CHAKRA_API
  1416. JsObjectGetOwnPropertyDescriptor(
  1417. _In_ JsValueRef object,
  1418. _In_ JsValueRef key,
  1419. _Out_ JsValueRef *propertyDescriptor);
  1420. /// <summary>
  1421. /// Determines whether an object has a non-inherited property.
  1422. /// </summary>
  1423. /// <remarks>
  1424. /// Requires an active script context.
  1425. /// </remarks>
  1426. /// <param name="object">The object that may contain the property.</param>
  1427. /// <param name="key">The key (JavascriptString or JavascriptSymbol) to the property.</param>
  1428. /// <param name="hasOwnProperty">Whether the object has the non-inherited property.</param>
  1429. /// <returns>
  1430. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1431. /// </returns>
  1432. CHAKRA_API
  1433. JsObjectHasOwnProperty(
  1434. _In_ JsValueRef object,
  1435. _In_ JsValueRef key,
  1436. _Out_ bool *hasOwnProperty);
  1437. /// <summary>
  1438. /// Sets whether any action should be taken when a promise is rejected with no reactions
  1439. /// or a reaction is added to a promise that was rejected before it had reactions.
  1440. /// By default in either of these cases nothing occurs.
  1441. /// This function allows you to specify if something should occur and provide a callback
  1442. /// to implement whatever should occur.
  1443. /// </summary>
  1444. /// <remarks>
  1445. /// Requires an active script context.
  1446. /// </remarks>
  1447. /// <param name="promiseRejectionTrackerCallback">The callback function being set.</param>
  1448. /// <param name="callbackState">
  1449. /// User provided state that will be passed back to the callback.
  1450. /// </param>
  1451. /// <returns>
  1452. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1453. /// </returns>
  1454. CHAKRA_API
  1455. JsSetHostPromiseRejectionTracker(
  1456. _In_ JsHostPromiseRejectionTrackerCallback promiseRejectionTrackerCallback,
  1457. _In_opt_ void *callbackState);
  1458. /// <summary>
  1459. /// Retrieve the namespace object for a module.
  1460. /// </summary>
  1461. /// <remarks>
  1462. /// Requires an active script context and that the module has already been evaluated.
  1463. /// </remarks>
  1464. /// <param name="requestModule">The JsModuleRecord for which the namespace is being requested.</param>
  1465. /// <param name="moduleNamespace">A JsValueRef - the requested namespace object.</param>
  1466. /// <returns>
  1467. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1468. /// </returns>
  1469. CHAKRA_API
  1470. JsGetModuleNamespace(
  1471. _In_ JsModuleRecord requestModule,
  1472. _Outptr_result_maybenull_ JsValueRef *moduleNamespace);
  1473. /// <summary>
  1474. /// Determines if a provided object is a JavscriptProxy Object and
  1475. /// provides references to a Proxy's target and handler.
  1476. /// </summary>
  1477. /// <remarks>
  1478. /// Requires an active script context.
  1479. /// If object is not a Proxy object the target and handler parameters are not touched.
  1480. /// If nullptr is supplied for target or handler the function returns after
  1481. /// setting the isProxy value.
  1482. /// If the object is a revoked Proxy target and handler are set to JS_INVALID_REFERENCE.
  1483. /// If it is a Proxy object that has not been revoked target and handler are set to the
  1484. /// the object's target and handler.
  1485. /// </remarks>
  1486. /// <param name="object">The object that may be a Proxy.</param>
  1487. /// <param name="isProxy">Pointer to a Boolean - is the object a proxy?</param>
  1488. /// <param name="target">Pointer to a JsValueRef - the object's target.</param>
  1489. /// <param name="handler">Pointer to a JsValueRef - the object's handler.</param>
  1490. /// <returns>
  1491. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1492. /// </returns>
  1493. CHAKRA_API
  1494. JsGetProxyProperties(
  1495. _In_ JsValueRef object,
  1496. _Out_ bool* isProxy,
  1497. _Out_opt_ JsValueRef* target,
  1498. _Out_opt_ JsValueRef* handler);
  1499. /// <summary>
  1500. /// Parses a script and stores the generated parser state cache into a buffer which can be reused.
  1501. /// </summary>
  1502. /// <remarks>
  1503. /// <para>
  1504. /// <c>JsSerializeParserState</c> parses a script and then stores a cache of the parser state
  1505. /// in a runtime-independent format. The parser state may be deserialized in any runtime along
  1506. /// with the same script to skip the initial parse phase.
  1507. /// </para>
  1508. /// <para>
  1509. /// Requires an active script context.
  1510. /// </para>
  1511. /// <para>
  1512. /// Script source can be either JavascriptString or JavascriptExternalArrayBuffer.
  1513. /// In case it is an ExternalArrayBuffer, and the encoding of the buffer is Utf16,
  1514. /// JsParseScriptAttributeArrayBufferIsUtf16Encoded is expected on parseAttributes.
  1515. /// </para>
  1516. /// <para>
  1517. /// Use JavascriptExternalArrayBuffer with Utf8/ASCII script source
  1518. /// for better performance and smaller memory footprint.
  1519. /// </para>
  1520. /// </remarks>
  1521. /// <param name="scriptVal">The script to parse.</param>
  1522. /// <param name="bufferVal">The buffer to put the serialized parser state cache into.</param>
  1523. /// <param name="parseAttributes">Encoding for the script.</param>
  1524. /// <returns>
  1525. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1526. /// </returns>
  1527. CHAKRA_API
  1528. JsSerializeParserState(
  1529. _In_ JsValueRef scriptVal,
  1530. _Out_ JsValueRef *bufferVal,
  1531. _In_ JsParseScriptAttributes parseAttributes);
  1532. /// <summary>
  1533. /// Deserializes the cache of initial parser state and (along with the same
  1534. /// script source) executes the script and returns the result.
  1535. /// </summary>
  1536. /// <remarks>
  1537. /// <para>
  1538. /// Requires an active script context.
  1539. /// </para>
  1540. /// <para>
  1541. /// Script source can be either JavascriptString or JavascriptExternalArrayBuffer.
  1542. /// In case it is an ExternalArrayBuffer, and the encoding of the buffer is Utf16,
  1543. /// JsParseScriptAttributeArrayBufferIsUtf16Encoded is expected on parseAttributes.
  1544. /// </para>
  1545. /// <para>
  1546. /// Use JavascriptExternalArrayBuffer with Utf8/ASCII script source
  1547. /// for better performance and smaller memory footprint.
  1548. /// </para>
  1549. /// </remarks>
  1550. /// <param name="script">The script to run.</param>
  1551. /// <param name="sourceContext">
  1552. /// A cookie identifying the script that can be used by debuggable script contexts.
  1553. /// </param>
  1554. /// <param name="sourceUrl">The location the script came from</param>
  1555. /// <param name="parseAttributes">Attribute mask for parsing the script</param>
  1556. /// <param name="parserState">
  1557. /// A buffer containing a cache of the parser state generated by <c>JsSerializeParserState</c>.
  1558. /// </param>
  1559. /// <param name="result">The result of the script, if any. This parameter can be null.</param>
  1560. /// <returns>
  1561. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1562. /// </returns>
  1563. CHAKRA_API
  1564. JsRunScriptWithParserState(
  1565. _In_ JsValueRef script,
  1566. _In_ JsSourceContext sourceContext,
  1567. _In_ JsValueRef sourceUrl,
  1568. _In_ JsParseScriptAttributes parseAttributes,
  1569. _In_ JsValueRef parserState,
  1570. _Out_ JsValueRef * result);
  1571. /// <summary>
  1572. /// Deserializes the cache of initial parser state and (along with the same
  1573. /// script source) returns a function representing that script.
  1574. /// </summary>
  1575. /// <remarks>
  1576. /// <para>
  1577. /// Requires an active script context.
  1578. /// </para>
  1579. /// <para>
  1580. /// Script source can be either JavascriptString or JavascriptExternalArrayBuffer.
  1581. /// In case it is an ExternalArrayBuffer, and the encoding of the buffer is Utf16,
  1582. /// JsParseScriptAttributeArrayBufferIsUtf16Encoded is expected on parseAttributes.
  1583. /// </para>
  1584. /// <para>
  1585. /// Use JavascriptExternalArrayBuffer with Utf8/ASCII script source
  1586. /// for better performance and smaller memory footprint.
  1587. /// </para>
  1588. /// </remarks>
  1589. /// <param name="script">The script to deserialize.</param>
  1590. /// <param name="sourceContext">
  1591. /// A cookie identifying the script that can be used by debuggable script contexts.
  1592. /// </param>
  1593. /// <param name="sourceUrl">The location the script came from</param>
  1594. /// <param name="parseAttributes">Attribute mask for parsing the script</param>
  1595. /// <param name="parserState">
  1596. /// A buffer containing a cache of the parser state generated by <c>JsSerializeParserState</c>.
  1597. /// </param>
  1598. /// <param name="result">A function representing the script. This parameter can be null.</param>
  1599. /// <returns>
  1600. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1601. /// </returns>
  1602. CHAKRA_API
  1603. JsDeserializeParserState(
  1604. _In_ JsValueRef script,
  1605. _In_ JsSourceContext sourceContext,
  1606. _In_ JsValueRef sourceUrl,
  1607. _In_ JsParseScriptAttributes parseAttributes,
  1608. _In_ JsValueRef parserState,
  1609. _Out_ JsValueRef* result);
  1610. typedef void (CHAKRA_CALLBACK *JsBeforeSweepCallback)(_In_opt_ void *callbackState);
  1611. CHAKRA_API
  1612. JsSetRuntimeBeforeSweepCallback(
  1613. _In_ JsRuntimeHandle runtimeHandle,
  1614. _In_opt_ void *callbackState,
  1615. _In_ JsBeforeSweepCallback beforeSweepCallback);
  1616. CHAKRA_API
  1617. JsSetRuntimeDomWrapperTracingCallbacks(
  1618. _In_ JsRuntimeHandle runtimeHandle,
  1619. _In_ JsRef wrapperTracingState,
  1620. _In_ JsDOMWrapperTracingCallback wrapperTracingCallback,
  1621. _In_ JsDOMWrapperTracingDoneCallback wrapperTracingDoneCallback,
  1622. _In_ JsDOMWrapperTracingEnterFinalPauseCallback enterFinalPauseCallback);
  1623. CHAKRA_API
  1624. JsTraceExternalReference(
  1625. _In_ JsRuntimeHandle runtimeHandle,
  1626. _In_ JsValueRef value
  1627. );
  1628. CHAKRA_API
  1629. JsAllocRawData(
  1630. _In_ JsRuntimeHandle runtimeHandle,
  1631. _In_ size_t sizeInBytes,
  1632. _In_ bool zeroed,
  1633. _Out_ JsRef * buffer
  1634. );
  1635. /// <summary>
  1636. /// A callback function to ask host to re-allocated buffer to the new size when the current buffer is full
  1637. /// </summary>
  1638. /// <param name="state">Pointer representing state of the serializer</param>
  1639. /// <param name="oldBuffer">An old memory buffer, which may be null, to be reallocated</param>
  1640. /// <param name="allocatedSize">Request host to allocate buffer of this size</param>
  1641. /// <param name="arrayBuffer">Actual size of the new buffer</param>
  1642. /// <returns>
  1643. /// New buffer will be returned upon success, null otherwise.
  1644. /// </returns>
  1645. typedef byte * (CHAKRA_CALLBACK *ReallocateBufferMemoryFunc)(void* state, byte *oldBuffer, size_t newSize, size_t *allocatedSize);
  1646. /// <summary>
  1647. /// A callback to ask host write current Host object to the serialization buffer.
  1648. /// </summary>
  1649. /// <returns>
  1650. /// A Boolean true is returned upon success, false otherwise.
  1651. /// </returns>
  1652. typedef bool (CHAKRA_CALLBACK *WriteHostObjectFunc)(void* state, void* hostObject);
  1653. /// <summary>
  1654. /// Initialize Serialization of the object.
  1655. /// </summary>
  1656. /// <param name="reallocateBufferMemory">A callback function to ask host to re-allocated buffer to the new size when the current buffer is full</param>
  1657. /// <param name="writeHostObject">A callback function to interact with host during serialization</param>
  1658. /// <param name="writeHostObject">A state object to pass to callback functions</param>
  1659. /// <param name="serializerHandle">A handle which provides various functionalities to serialize objects</param>
  1660. /// <returns>
  1661. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1662. /// </returns>
  1663. CHAKRA_API
  1664. JsVarSerializer(
  1665. _In_ ReallocateBufferMemoryFunc reallocateBufferMemory,
  1666. _In_ WriteHostObjectFunc writeHostObject,
  1667. _In_opt_ void * callbackState,
  1668. _Out_ JsVarSerializerHandle *serializerHandle);
  1669. /// <summary>
  1670. /// Write raw bytes to the buffer.
  1671. /// </summary>
  1672. /// <param name="source">Source byte buffer</param>
  1673. /// <param name="length">Length of bytes to write from source raw byte buffer</param>
  1674. /// <returns>
  1675. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1676. /// </returns>
  1677. CHAKRA_API
  1678. JsVarSerializerWriteRawBytes(
  1679. _In_ JsVarSerializerHandle serializerHandle,
  1680. _In_ const void* source,
  1681. _In_ size_t length);
  1682. /// <summary>
  1683. /// A method to serialize given Javascript object to the serialization buffer
  1684. /// </summary>
  1685. /// <param name="rootObject">A Javascript object to be serialized</param>
  1686. /// <returns>
  1687. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1688. /// </returns>
  1689. CHAKRA_API
  1690. JsVarSerializerWriteValue(
  1691. _In_ JsVarSerializerHandle serializerHandle,
  1692. _In_ JsValueRef rootObject);
  1693. /// <summary>
  1694. /// A method to pass on the current serialized buffer (this buffer was allocated using ReallocateBufferMemory) to host.
  1695. /// </summary>
  1696. /// <param name="data">A buffer which holds current serialized data</param>
  1697. /// <param name="dataLength">Length of the buffer</param>
  1698. /// <returns>
  1699. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1700. /// </returns>
  1701. CHAKRA_API
  1702. JsVarSerializerReleaseData(
  1703. _In_ JsVarSerializerHandle serializerHandle,
  1704. _Out_ byte** data,
  1705. _Out_ size_t *dataLength);
  1706. /// <summary>
  1707. /// Detach all array buffers which were passed using SetTransferableVars.
  1708. /// </summary>
  1709. /// <returns>
  1710. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1711. /// </returns>
  1712. CHAKRA_API
  1713. JsVarSerializerDetachArrayBuffer(_In_ JsVarSerializerHandle serializerHandle);
  1714. /// <summary>
  1715. /// Host provides all the objects which has transferable semantics (Such as ArrayBuffers).
  1716. /// </summary>
  1717. /// <param name="transferableVars">An array of transferable objects</param>
  1718. /// <param name="transferableVarsCount">Length of transferableVars array </param>
  1719. /// <returns>
  1720. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1721. /// </returns>
  1722. CHAKRA_API
  1723. JsVarSerializerSetTransferableVars(
  1724. _In_ JsVarSerializerHandle serializerHandle,
  1725. _In_opt_ JsValueRef *transferableVars,
  1726. _In_ size_t transferableVarsCount);
  1727. /// <summary>
  1728. /// Free current object (which was created upon JsVarSerializer) when the serialization is done. SerializerHandleBase object should not be used further after FreeSelf call.
  1729. /// </summary>
  1730. /// <returns>
  1731. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1732. /// </returns>
  1733. CHAKRA_API
  1734. JsVarSerializerFree(_In_ JsVarSerializerHandle serializerHandle);
  1735. /// <summary>
  1736. /// A callback to ask host to read the current data from the serialization buffer as a Host object.
  1737. /// </summary>
  1738. /// <returns>
  1739. /// A valid host object is returned upon success, an exception is thrown otherwise.
  1740. /// </returns>
  1741. typedef JsValueRef(*ReadHostObjectFunc)(void* state);
  1742. /// <summary>
  1743. /// A callback to ask host to retrieve SharedArrayBuffer object from given ID.
  1744. /// </summary>
  1745. /// <param name="id">An ID, which was provided by SerializerCallbackBase::GetSharedArrayBufferId method</param>
  1746. /// <returns>
  1747. /// A valid SharedArrayBuffer is returned upon success, an exception is thrown otherwise.
  1748. /// </returns>
  1749. typedef JsValueRef(*GetSharedArrayBufferFromIdFunc)(void* state, uint32_t id);
  1750. /// <summary>
  1751. /// Initiate Deserialization of the memory buffer to a Javascript object.
  1752. /// </summary>
  1753. /// <param name="data">A memory buffer which holds the serialized data</param>
  1754. /// <param name="size">Length of the passed data in bytes</param>
  1755. /// <param name="ReadHostObjectFunc">A callback to ask host to read the current data from the serialization buffer as a Host object.</param>
  1756. /// <param name="GetSharedArrayBufferFromIdFunc">A callback to ask host to retrieve SharedArrayBuffer object from given ID.</param>
  1757. /// <param name="callbackState">A callback object to interact with host during deserialization</param>
  1758. /// <param name="deserializerHandle">A handle which provides various functionalities to deserailize a buffer to an object</param>
  1759. /// <returns>
  1760. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1761. /// </returns>
  1762. CHAKRA_API
  1763. JsVarDeserializer(
  1764. _In_ void *data,
  1765. _In_ size_t size,
  1766. _In_ ReadHostObjectFunc readHostObject,
  1767. _In_ GetSharedArrayBufferFromIdFunc getSharedArrayBufferFromId,
  1768. _In_opt_ void* callbackState,
  1769. _Out_ JsVarDeserializerHandle *deserializerHandle);
  1770. /// <summary>
  1771. /// A method to read bytes from the serialized buffer. Caller should not allocate the data buffer.
  1772. /// </summary>
  1773. /// <param name="length">Advance current buffer's position by length</param>
  1774. /// <param name="data">The data will be pointing to the raw serialized buffer</param>
  1775. /// <returns>
  1776. /// A Boolean value true is returned upon success, false otherwise.
  1777. /// </returns>
  1778. CHAKRA_API
  1779. JsVarDeserializerReadRawBytes(_In_ JsVarDeserializerHandle deserializerHandle, _In_ size_t length, _Out_ void **data);
  1780. /// <summary>
  1781. /// A method to read bytes from the serialized buffer. Caller must allocate data buffer by length.
  1782. /// </summary>
  1783. /// <param name="length">Length of data buffer</param>
  1784. /// <param name="data">data buffer to be populated from the serialized buffer till the given length</param>
  1785. /// <returns>
  1786. /// A Boolean value true is returned upon success, false otherwise.
  1787. /// </returns>
  1788. CHAKRA_API
  1789. JsVarDeserializerReadBytes(_In_ JsVarDeserializerHandle deserializerHandle, _In_ size_t length, _Out_ void **data);
  1790. /// <summary>
  1791. /// Deserialized current buffer and pass the root object.
  1792. /// </summary>
  1793. /// <returns>
  1794. /// A valid Javascript object is returned upon success, an exception is thrown otherwise.
  1795. /// </returns>
  1796. CHAKRA_API
  1797. JsVarDeserializerReadValue(_In_ JsVarDeserializerHandle deserializerHandle, _Out_ JsValueRef* value);
  1798. /// <summary>
  1799. /// Host provides all the objects which has transferable semantics (Such as ArrayBuffers).
  1800. /// </summary>
  1801. /// <param name="transferableVars">An array of transferable objects</param>
  1802. /// <param name="transferableVarsCount">Length of transferableVars array </param>
  1803. /// <returns>
  1804. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1805. /// </returns>
  1806. CHAKRA_API
  1807. JsVarDeserializerSetTransferableVars(_In_ JsVarDeserializerHandle deserializerHandle, _In_opt_ JsValueRef *transferableVars, _In_ size_t transferableVarsCount);
  1808. /// <summary>
  1809. /// Free current object (which was created upon JsVarSerializer) when the serialization is done. JsVarSerializerHandle object should not be used further after FreeSelf call.
  1810. /// </summary>
  1811. /// <returns>
  1812. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1813. /// </returns>
  1814. CHAKRA_API
  1815. JsVarDeserializerFree(_In_ JsVarDeserializerHandle deserializerHandle);
  1816. /// <summary>
  1817. /// Extract extra info stored from an ArrayBuffer object
  1818. /// </summary>
  1819. /// <param name="arrayBuffer">An ArrayBuffer from which the extrainfor needed to extracted</param>
  1820. /// <param name="extraInfo">The host information (some flags such as object externalized, detached) stored in the object</param>
  1821. /// <returns>
  1822. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1823. /// </returns>
  1824. CHAKRA_API
  1825. JsGetArrayBufferExtraInfo(
  1826. _In_ JsValueRef arrayBuffer,
  1827. _Out_ char *extraInfo);
  1828. /// <summary>
  1829. /// Set Extra info (host data) to an ArrayBuffer object.
  1830. /// </summary>
  1831. /// <param name="arrayBuffer">An ArrayBuffer on which the host information will be stored</param>
  1832. /// <param name="extraInfo">The host data</param>
  1833. /// <returns>
  1834. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1835. /// </returns>
  1836. CHAKRA_API
  1837. JsSetArrayBufferExtraInfo(
  1838. _In_ JsValueRef arrayBuffer,
  1839. _In_ char extraInfo);
  1840. /// <summary>
  1841. /// Neuter current ArrayBuffer
  1842. /// </summary>
  1843. /// <param name="arrayBuffer">An ArrayBuffer which will be neutered </param>
  1844. /// <returns>
  1845. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1846. /// </returns>
  1847. CHAKRA_API
  1848. JsDetachArrayBuffer(
  1849. _In_ JsValueRef arrayBuffer);
  1850. typedef void(__cdecl *ArrayBufferFreeFn)(void*);
  1851. /// <summary>
  1852. /// Returns the function which free the underlying buffer of ArrayBuffer
  1853. /// </summary>
  1854. /// <param name="arrayBuffer">An ArrayBuffer for which Free function to be returned </param>
  1855. /// <param name="freeFn">Free function will be returned</param>
  1856. /// <returns>
  1857. /// The code <c>JsNoError</c> if the operation succeeded, a failure code
  1858. /// otherwise.
  1859. /// </returns>
  1860. CHAKRA_API
  1861. JsGetArrayBufferFreeFunction(
  1862. _In_ JsValueRef arrayBuffer,
  1863. _Out_ ArrayBufferFreeFn* freeFn);
  1864. /// <summary>
  1865. /// Take ownership of current ArrayBuffer
  1866. /// </summary>
  1867. /// <param name="arrayBuffer">An ArrayBuffer to take ownership of</param>
  1868. /// <returns>
  1869. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1870. /// </returns>
  1871. CHAKRA_API
  1872. JsExternalizeArrayBuffer(
  1873. _In_ JsValueRef arrayBuffer);
  1874. /// <summary>
  1875. /// Get host embedded data from the current object
  1876. /// </summary>
  1877. /// <param name="instance">Js object from which an embedder data to be fetched</param>
  1878. /// <param name="embedderData">An embedder data to be returned, it will be nullptr if not found</param>
  1879. /// <returns>
  1880. /// The code <c>JsNoError</c> if the operation succeeded, a failure code
  1881. /// otherwise.
  1882. /// </returns>
  1883. CHAKRA_API
  1884. JsGetEmbedderData(_In_ JsValueRef instance, _Out_ JsValueRef* embedderData);
  1885. /// <summary>
  1886. /// Set host embedded data on the current object
  1887. /// </summary>
  1888. /// <param name="instance">Js object from which an embedder data to be fetched</param>
  1889. /// <param name="embedderData">An embedder data to be set on the passed object</param>
  1890. /// <returns>
  1891. /// The code <c>JsNoError</c> if the operation succeeded, a failure code
  1892. /// otherwise.
  1893. /// </returns>
  1894. CHAKRA_API
  1895. JsSetEmbedderData(_In_ JsValueRef instance, _In_ JsValueRef embedderData);
  1896. #ifdef _WIN32
  1897. #include "ChakraCoreWindows.h"
  1898. #endif // _WIN32
  1899. #endif // _CHAKRACOREBUILD
  1900. #endif // _CHAKRACORE_H_