ChakraCore.h 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  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. typedef void* JsModuleRecord;
  28. /// <summary>
  29. /// A reference to an object owned by the SharedArrayBuffer.
  30. /// </summary>
  31. /// <remarks>
  32. /// This represents SharedContents which is heap allocated object, it can be passed through
  33. /// different runtimes to share the underlying buffer.
  34. /// </remarks>
  35. typedef void *JsSharedArrayBufferContentHandle;
  36. typedef enum JsParseModuleSourceFlags
  37. {
  38. JsParseModuleSourceFlags_DataIsUTF16LE = 0x00000000,
  39. JsParseModuleSourceFlags_DataIsUTF8 = 0x00000001
  40. } JsParseModuleSourceFlags;
  41. typedef enum JsModuleHostInfoKind
  42. {
  43. JsModuleHostInfo_Exception = 0x01,
  44. JsModuleHostInfo_HostDefined = 0x02,
  45. JsModuleHostInfo_NotifyModuleReadyCallback = 0x3,
  46. JsModuleHostInfo_FetchImportedModuleCallback = 0x4,
  47. JsModuleHostInfo_FetchImportedModuleFromScriptCallback = 0x5,
  48. JsModuleHostInfo_Url = 0x6
  49. } JsModuleHostInfoKind;
  50. /// <summary>
  51. /// The possible states for a Promise object.
  52. /// </summary>
  53. typedef enum _JsPromiseState
  54. {
  55. JsPromiseStatePending = 0x0,
  56. JsPromiseStateFulfilled = 0x1,
  57. JsPromiseStateRejected = 0x2
  58. } JsPromiseState;
  59. /// <summary>
  60. /// User implemented callback to fetch additional imported modules.
  61. /// </summary>
  62. /// <remarks>
  63. /// Notify the host to fetch the dependent module. This is the "import" part before HostResolveImportedModule in ES6 spec.
  64. /// This notifies the host that the referencing module has the specified module dependency, and the host need to retrieve the module back.
  65. /// </remarks>
  66. /// <param name="referencingModule">The referencing module that is requesting the dependency modules.</param>
  67. /// <param name="specifier">The specifier coming from the module source code.</param>
  68. /// <param name="dependentModuleRecord">The ModuleRecord of the dependent module. If the module was requested before from other source, return the
  69. /// existing ModuleRecord, otherwise return a newly created ModuleRecord.</param>
  70. /// <returns>
  71. /// true if the operation succeeded, false otherwise.
  72. /// </returns>
  73. typedef JsErrorCode(CHAKRA_CALLBACK * FetchImportedModuleCallBack)(_In_ JsModuleRecord referencingModule, _In_ JsValueRef specifier, _Outptr_result_maybenull_ JsModuleRecord* dependentModuleRecord);
  74. /// <summary>
  75. /// User implemented callback to get notification when the module is ready.
  76. /// </summary>
  77. /// <remarks>
  78. /// Notify the host after ModuleDeclarationInstantiation step (15.2.1.1.6.4) is finished. If there was error in the process, exceptionVar
  79. /// holds the exception. Otherwise the referencingModule is ready and the host should schedule execution afterwards.
  80. /// </remarks>
  81. /// <param name="referencingModule">The referencing module that have finished running ModuleDeclarationInstantiation step.</param>
  82. /// <param name="exceptionVar">If nullptr, the module is successfully initialized and host should queue the execution job
  83. /// otherwise it's the exception object.</param>
  84. /// <returns>
  85. /// true if the operation succeeded, false otherwise.
  86. /// </returns>
  87. typedef JsErrorCode(CHAKRA_CALLBACK * FetchImportedModuleFromScriptCallBack)(_In_ JsSourceContext dwReferencingSourceContext, _In_ JsValueRef specifier, _Outptr_result_maybenull_ JsModuleRecord* dependentModuleRecord);
  88. /// <summary>
  89. /// User implemented callback to get notification when the module is ready.
  90. /// </summary>
  91. /// <remarks>
  92. /// Notify the host after ModuleDeclarationInstantiation step (15.2.1.1.6.4) is finished. If there was error in the process, exceptionVar
  93. /// holds the exception. Otherwise the referencingModule is ready and the host should schedule execution afterwards.
  94. /// </remarks>
  95. /// <param name="dwReferencingSourceContext">The referencing script that calls import()</param>
  96. /// <param name="exceptionVar">If nullptr, the module is successfully initialized and host should queue the execution job
  97. /// otherwise it's the exception object.</param>
  98. /// <returns>
  99. /// true if the operation succeeded, false otherwise.
  100. /// </returns>
  101. typedef JsErrorCode(CHAKRA_CALLBACK * NotifyModuleReadyCallback)(_In_opt_ JsModuleRecord referencingModule, _In_opt_ JsValueRef exceptionVar);
  102. /// <summary>
  103. /// A structure containing information about a native function callback.
  104. /// </summary>
  105. typedef struct JsNativeFunctionInfo
  106. {
  107. JsValueRef thisArg;
  108. JsValueRef newTargetArg;
  109. bool isConstructCall;
  110. }JsNativeFunctionInfo;
  111. /// <summary>
  112. /// A function callback.
  113. /// </summary>
  114. /// <param name="callee">
  115. /// A function object that represents the function being invoked.
  116. /// </param>
  117. /// <param name="arguments">The arguments to the call.</param>
  118. /// <param name="argumentCount">The number of arguments.</param>
  119. /// <param name="info">Additional information about this function call.</param>
  120. /// <param name="callbackState">
  121. /// The state passed to <c>JsCreateFunction</c>.
  122. /// </param>
  123. /// <returns>The result of the call, if any.</returns>
  124. typedef _Ret_maybenull_ JsValueRef(CHAKRA_CALLBACK * JsEnhancedNativeFunction)(_In_ JsValueRef callee, _In_ JsValueRef *arguments, _In_ unsigned short argumentCount, _In_ JsNativeFunctionInfo *info, _In_opt_ void *callbackState);
  125. /// <summary>
  126. /// A Promise Rejection Tracker callback.
  127. /// </summary>
  128. /// <remarks>
  129. /// The host can specify a promise rejection tracker callback in <c>JsSetHostPromiseRejectionTracker</c>.
  130. /// If a promise is rejected with no reactions or a reaction is added to a promise that was rejected
  131. /// before it had reactions by default nothing is done.
  132. /// A Promise Rejection Tracker callback may be set - which will then be called when this occurs.
  133. /// Note - per draft ECMASpec 2018 25.4.1.9 this function should not set or return an exception
  134. /// Note also the promise and reason parameters may be garbage collected after this function is called
  135. /// if you wish to make further use of them you will need to use JsAddRef to preserve them
  136. /// However if you use JsAddRef you must also call JsRelease and not hold unto them after
  137. /// a handled notification (both per spec and to avoid memory leaks)
  138. /// </remarks>
  139. /// <param name="promise">The promise object, represented as a JsValueRef.</param>
  140. /// <param name="reason">The value/cause of the rejection, represented as a JsValueRef.</param>
  141. /// <param name="handled">Boolean - false for promiseRejected: i.e. if the promise has just been rejected with no handler,
  142. /// true for promiseHandled: i.e. if it was rejected before without a handler and is now being handled.</param>
  143. /// <param name="callbackState">The state passed to <c>JsSetHostPromiseRejectionTracker</c>.</param>
  144. typedef void (CHAKRA_CALLBACK *JsHostPromiseRejectionTrackerCallback)(_In_ JsValueRef promise, _In_ JsValueRef reason, _In_ bool handled, _In_opt_ void *callbackState);
  145. /// <summary>
  146. /// Creates a new enhanced JavaScript function.
  147. /// </summary>
  148. /// <remarks>
  149. /// Requires an active script context.
  150. /// </remarks>
  151. /// <param name="nativeFunction">The method to call when the function is invoked.</param>
  152. /// <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>
  153. /// <param name="callbackState">
  154. /// User provided state that will be passed back to the callback.
  155. /// </param>
  156. /// <param name="function">The new function object.</param>
  157. /// <returns>
  158. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  159. /// </returns>
  160. CHAKRA_API
  161. JsCreateEnhancedFunction(
  162. _In_ JsEnhancedNativeFunction nativeFunction,
  163. _In_opt_ JsValueRef metadata,
  164. _In_opt_ void *callbackState,
  165. _Out_ JsValueRef *function);
  166. /// <summary>
  167. /// Initialize a ModuleRecord from host
  168. /// </summary>
  169. /// <remarks>
  170. /// Bootstrap the module loading process by creating a new module record.
  171. /// </remarks>
  172. /// <param name="referencingModule">The referencingModule as in HostResolveImportedModule (15.2.1.17). nullptr if this is the top level module.</param>
  173. /// <param name="normalizedSpecifier">The host normalized specifier. This is the key to a unique ModuleRecord.</param>
  174. /// <param name="moduleRecord">The new ModuleRecord created. The host should not try to call this API twice with the same normalizedSpecifier.
  175. /// chakra will return an existing ModuleRecord if the specifier was passed in before.</param>
  176. /// <returns>
  177. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  178. /// </returns>
  179. CHAKRA_API
  180. JsInitializeModuleRecord(
  181. _In_opt_ JsModuleRecord referencingModule,
  182. _In_ JsValueRef normalizedSpecifier,
  183. _Outptr_result_maybenull_ JsModuleRecord* moduleRecord);
  184. /// <summary>
  185. /// Parse the module source
  186. /// </summary>
  187. /// <remarks>
  188. /// This is basically ParseModule operation in ES6 spec. It is slightly different in that the ModuleRecord was initialized earlier, and passed in as an argument.
  189. /// </remarks>
  190. /// <param name="requestModule">The ModuleRecord that holds the parse tree of the source code.</param>
  191. /// <param name="sourceContext">A cookie identifying the script that can be used by debuggable script contexts.</param>
  192. /// <param name="script">The source script to be parsed, but not executed in this code.</param>
  193. /// <param name="scriptLength">The source length of sourceText. The input might contain embedded null.</param>
  194. /// <param name="sourceFlag">The type of the source code passed in. It could be UNICODE or utf8 at this time.</param>
  195. /// <param name="exceptionValueRef">The error object if there is parse error.</param>
  196. /// <returns>
  197. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  198. /// </returns>
  199. CHAKRA_API
  200. JsParseModuleSource(
  201. _In_ JsModuleRecord requestModule,
  202. _In_ JsSourceContext sourceContext,
  203. _In_ BYTE* script,
  204. _In_ unsigned int scriptLength,
  205. _In_ JsParseModuleSourceFlags sourceFlag,
  206. _Outptr_result_maybenull_ JsValueRef* exceptionValueRef);
  207. /// <summary>
  208. /// Execute module code.
  209. /// </summary>
  210. /// <remarks>
  211. /// This method implements 15.2.1.1.6.5, "ModuleEvaluation" concrete method.
  212. /// When this methid is called, the chakra engine should have notified the host that the module and all its dependent are ready to be executed.
  213. /// One moduleRecord will be executed only once. Additional execution call on the same moduleRecord will fail.
  214. /// </remarks>
  215. /// <param name="requestModule">The module to be executed.</param>
  216. /// <param name="result">The return value of the module.</param>
  217. /// <returns>
  218. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  219. /// </returns>
  220. CHAKRA_API
  221. JsModuleEvaluation(
  222. _In_ JsModuleRecord requestModule,
  223. _Outptr_result_maybenull_ JsValueRef* result);
  224. /// <summary>
  225. /// Set the host info for the specified module.
  226. /// </summary>
  227. /// <param name="requestModule">The request module.</param>
  228. /// <param name="moduleHostInfo">The type of host info to be set.</param>
  229. /// <param name="hostInfo">The host info to be set.</param>
  230. /// <returns>
  231. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  232. /// </returns>
  233. CHAKRA_API
  234. JsSetModuleHostInfo(
  235. _In_ JsModuleRecord requestModule,
  236. _In_ JsModuleHostInfoKind moduleHostInfo,
  237. _In_ void* hostInfo);
  238. /// <summary>
  239. /// Retrieve the host info for the specified module.
  240. /// </summary>
  241. /// <param name="requestModule">The request module.</param>
  242. /// <param name="moduleHostInfo">The type of host info to get.</param>
  243. /// <param name="hostInfo">The host info to be retrieved.</param>
  244. /// <returns>
  245. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  246. /// </returns>
  247. CHAKRA_API
  248. JsGetModuleHostInfo(
  249. _In_ JsModuleRecord requestModule,
  250. _In_ JsModuleHostInfoKind moduleHostInfo,
  251. _Outptr_result_maybenull_ void** hostInfo);
  252. /// <summary>
  253. /// Returns metadata relating to the exception that caused the runtime of the current context
  254. /// to be in the exception state and resets the exception state for that runtime. The metadata
  255. /// includes a reference to the exception itself.
  256. /// </summary>
  257. /// <remarks>
  258. /// <para>
  259. /// If the runtime of the current context is not in an exception state, this API will return
  260. /// <c>JsErrorInvalidArgument</c>. If the runtime is disabled, this will return an exception
  261. /// indicating that the script was terminated, but it will not clear the exception (the
  262. /// exception will be cleared if the runtime is re-enabled using
  263. /// <c>JsEnableRuntimeExecution</c>).
  264. /// </para>
  265. /// <para>
  266. /// The metadata value is a javascript object with the following properties: <c>exception</c>, the
  267. /// thrown exception object; <c>line</c>, the 0 indexed line number where the exception was thrown;
  268. /// <c>column</c>, the 0 indexed column number where the exception was thrown; <c>length</c>, the
  269. /// source-length of the cause of the exception; <c>source</c>, a string containing the line of
  270. /// source code where the exception was thrown; and <c>url</c>, a string containing the name of
  271. /// the script file containing the code that threw the exception.
  272. /// </para>
  273. /// <para>
  274. /// Requires an active script context.
  275. /// </para>
  276. /// </remarks>
  277. /// <param name="metadata">The exception metadata for the runtime of the current context.</param>
  278. /// <returns>
  279. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  280. /// </returns>
  281. CHAKRA_API
  282. JsGetAndClearExceptionWithMetadata(
  283. _Out_ JsValueRef *metadata);
  284. /// <summary>
  285. /// Called by the runtime to load the source code of the serialized script.
  286. /// </summary>
  287. /// <param name="sourceContext">The context passed to Js[Parse|Run]SerializedScriptCallback</param>
  288. /// <param name="script">The script returned.</param>
  289. /// <returns>
  290. /// true if the operation succeeded, false otherwise.
  291. /// </returns>
  292. typedef bool (CHAKRA_CALLBACK * JsSerializedLoadScriptCallback)
  293. (JsSourceContext sourceContext, _Out_ JsValueRef *value,
  294. _Out_ JsParseScriptAttributes *parseAttributes);
  295. /// <summary>
  296. /// Create JavascriptString variable from ASCII or Utf8 string
  297. /// </summary>
  298. /// <remarks>
  299. /// <para>
  300. /// Requires an active script context.
  301. /// </para>
  302. /// <para>
  303. /// Input string can be either ASCII or Utf8
  304. /// </para>
  305. /// </remarks>
  306. /// <param name="content">Pointer to string memory.</param>
  307. /// <param name="length">Number of bytes within the string</param>
  308. /// <param name="value">JsValueRef representing the JavascriptString</param>
  309. /// <returns>
  310. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  311. /// </returns>
  312. CHAKRA_API
  313. JsCreateString(
  314. _In_ const char *content,
  315. _In_ size_t length,
  316. _Out_ JsValueRef *value);
  317. /// <summary>
  318. /// Create JavascriptString variable from Utf16 string
  319. /// </summary>
  320. /// <remarks>
  321. /// <para>
  322. /// Requires an active script context.
  323. /// </para>
  324. /// <para>
  325. /// Expects Utf16 string
  326. /// </para>
  327. /// </remarks>
  328. /// <param name="content">Pointer to string memory.</param>
  329. /// <param name="length">Number of characters within the string</param>
  330. /// <param name="value">JsValueRef representing the JavascriptString</param>
  331. /// <returns>
  332. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  333. /// </returns>
  334. CHAKRA_API
  335. JsCreateStringUtf16(
  336. _In_ const uint16_t *content,
  337. _In_ size_t length,
  338. _Out_ JsValueRef *value);
  339. /// <summary>
  340. /// Write JavascriptString value into C string buffer (Utf8)
  341. /// </summary>
  342. /// <remarks>
  343. /// <para>
  344. /// When size of the `buffer` is unknown,
  345. /// `buffer` argument can be nullptr.
  346. /// In that case, `length` argument will return the length needed.
  347. /// </para>
  348. /// </remarks>
  349. /// <param name="value">JavascriptString value</param>
  350. /// <param name="buffer">Pointer to buffer</param>
  351. /// <param name="bufferSize">Buffer size</param>
  352. /// <param name="length">Total number of characters needed or written</param>
  353. /// <returns>
  354. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  355. /// </returns>
  356. CHAKRA_API
  357. JsCopyString(
  358. _In_ JsValueRef value,
  359. _Out_opt_ char* buffer,
  360. _In_ size_t bufferSize,
  361. _Out_opt_ size_t* length);
  362. /// <summary>
  363. /// Write string value into Utf16 string buffer
  364. /// </summary>
  365. /// <remarks>
  366. /// <para>
  367. /// When size of the `buffer` is unknown,
  368. /// `buffer` argument can be nullptr.
  369. /// In that case, `written` argument will return the length needed.
  370. /// </para>
  371. /// <para>
  372. /// when start is out of range or &lt; 0, returns JsErrorInvalidArgument
  373. /// and `written` will be equal to 0.
  374. /// If calculated length is 0 (It can be due to string length or `start`
  375. /// and length combination), then `written` will be equal to 0 and call
  376. /// returns JsNoError
  377. /// </para>
  378. /// </remarks>
  379. /// <param name="value">JavascriptString value</param>
  380. /// <param name="start">start offset of buffer</param>
  381. /// <param name="length">length to be written</param>
  382. /// <param name="buffer">Pointer to buffer</param>
  383. /// <param name="written">Total number of characters written</param>
  384. /// <returns>
  385. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  386. /// </returns>
  387. CHAKRA_API
  388. JsCopyStringUtf16(
  389. _In_ JsValueRef value,
  390. _In_ int start,
  391. _In_ int length,
  392. _Out_opt_ uint16_t* buffer,
  393. _Out_opt_ size_t* written);
  394. /// <summary>
  395. /// Parses a script and returns a function representing the script.
  396. /// </summary>
  397. /// <remarks>
  398. /// <para>
  399. /// Requires an active script context.
  400. /// </para>
  401. /// <para>
  402. /// Script source can be either JavascriptString or JavascriptExternalArrayBuffer.
  403. /// In case it is an ExternalArrayBuffer, and the encoding of the buffer is Utf16,
  404. /// JsParseScriptAttributeArrayBufferIsUtf16Encoded is expected on parseAttributes.
  405. /// </para>
  406. /// <para>
  407. /// Use JavascriptExternalArrayBuffer with Utf8/ASCII script source
  408. /// for better performance and smaller memory footprint.
  409. /// </para>
  410. /// </remarks>
  411. /// <param name="script">The script to run.</param>
  412. /// <param name="sourceContext">
  413. /// A cookie identifying the script that can be used by debuggable script contexts.
  414. /// </param>
  415. /// <param name="sourceUrl">The location the script came from.</param>
  416. /// <param name="parseAttributes">Attribute mask for parsing the script</param>
  417. /// <param name="result">The result of the compiled script.</param>
  418. /// <returns>
  419. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  420. /// </returns>
  421. CHAKRA_API
  422. JsParse(
  423. _In_ JsValueRef script,
  424. _In_ JsSourceContext sourceContext,
  425. _In_ JsValueRef sourceUrl,
  426. _In_ JsParseScriptAttributes parseAttributes,
  427. _Out_ JsValueRef *result);
  428. /// <summary>
  429. /// Executes a script.
  430. /// </summary>
  431. /// <remarks>
  432. /// <para>
  433. /// Requires an active script context.
  434. /// </para>
  435. /// <para>
  436. /// Script source can be either JavascriptString or JavascriptExternalArrayBuffer.
  437. /// In case it is an ExternalArrayBuffer, and the encoding of the buffer is Utf16,
  438. /// JsParseScriptAttributeArrayBufferIsUtf16Encoded is expected on parseAttributes.
  439. /// </para>
  440. /// <para>
  441. /// Use JavascriptExternalArrayBuffer with Utf8/ASCII script source
  442. /// for better performance and smaller memory footprint.
  443. /// </para>
  444. /// </remarks>
  445. /// <param name="script">The script to run.</param>
  446. /// <param name="sourceContext">
  447. /// A cookie identifying the script that can be used by debuggable script contexts.
  448. /// </param>
  449. /// <param name="sourceUrl">The location the script came from</param>
  450. /// <param name="parseAttributes">Attribute mask for parsing the script</param>
  451. /// <param name="result">The result of the script, if any. This parameter can be null.</param>
  452. /// <returns>
  453. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  454. /// </returns>
  455. CHAKRA_API
  456. JsRun(
  457. _In_ JsValueRef script,
  458. _In_ JsSourceContext sourceContext,
  459. _In_ JsValueRef sourceUrl,
  460. _In_ JsParseScriptAttributes parseAttributes,
  461. _Out_ JsValueRef *result);
  462. /// <summary>
  463. /// Creates the property ID associated with the name.
  464. /// </summary>
  465. /// <remarks>
  466. /// <para>
  467. /// Property IDs are specific to a context and cannot be used across contexts.
  468. /// </para>
  469. /// <para>
  470. /// Requires an active script context.
  471. /// </para>
  472. /// </remarks>
  473. /// <param name="name">
  474. /// The name of the property ID to get or create. The name may consist of only digits.
  475. /// The string is expected to be ASCII / utf8 encoded.
  476. /// </param>
  477. /// <param name="length">length of the name in bytes</param>
  478. /// <param name="propertyId">The property ID in this runtime for the given name.</param>
  479. /// <returns>
  480. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  481. /// </returns>
  482. CHAKRA_API
  483. JsCreatePropertyId(
  484. _In_z_ const char *name,
  485. _In_ size_t length,
  486. _Out_ JsPropertyIdRef *propertyId);
  487. /// <summary>
  488. /// Copies the name associated with the property ID into a buffer.
  489. /// </summary>
  490. /// <remarks>
  491. /// <para>
  492. /// Requires an active script context.
  493. /// </para>
  494. /// <para>
  495. /// When size of the `buffer` is unknown,
  496. /// `buffer` argument can be nullptr.
  497. /// `length` argument will return the size needed.
  498. /// </para>
  499. /// </remarks>
  500. /// <param name="propertyId">The property ID to get the name of.</param>
  501. /// <param name="buffer">The buffer holding the name associated with the property ID, encoded as utf8</param>
  502. /// <param name="bufferSize">Size of the buffer.</param>
  503. /// <param name="written">Total number of characters written or to be written</param>
  504. /// <returns>
  505. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  506. /// </returns>
  507. CHAKRA_API
  508. JsCopyPropertyId(
  509. _In_ JsPropertyIdRef propertyId,
  510. _Out_ char* buffer,
  511. _In_ size_t bufferSize,
  512. _Out_ size_t* length);
  513. /// <summary>
  514. /// Serializes a parsed script to a buffer than can be reused.
  515. /// </summary>
  516. /// <remarks>
  517. /// <para>
  518. /// <c>JsSerializeScript</c> parses a script and then stores the parsed form of the script in a
  519. /// runtime-independent format. The serialized script then can be deserialized in any
  520. /// runtime without requiring the script to be re-parsed.
  521. /// </para>
  522. /// <para>
  523. /// Requires an active script context.
  524. /// </para>
  525. /// <para>
  526. /// Script source can be either JavascriptString or JavascriptExternalArrayBuffer.
  527. /// In case it is an ExternalArrayBuffer, and the encoding of the buffer is Utf16,
  528. /// JsParseScriptAttributeArrayBufferIsUtf16Encoded is expected on parseAttributes.
  529. /// </para>
  530. /// <para>
  531. /// Use JavascriptExternalArrayBuffer with Utf8/ASCII script source
  532. /// for better performance and smaller memory footprint.
  533. /// </para>
  534. /// </remarks>
  535. /// <param name="script">The script to serialize</param>
  536. /// <param name="buffer">ArrayBuffer</param>
  537. /// <param name="parseAttributes">Encoding for the script.</param>
  538. /// <returns>
  539. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  540. /// </returns>
  541. CHAKRA_API
  542. JsSerialize(
  543. _In_ JsValueRef script,
  544. _Out_ JsValueRef *buffer,
  545. _In_ JsParseScriptAttributes parseAttributes);
  546. /// <summary>
  547. /// Parses a serialized script and returns a function representing the script.
  548. /// Provides the ability to lazy load the script source only if/when it is needed.
  549. /// </summary>
  550. /// <remarks>
  551. /// <para>
  552. /// Requires an active script context.
  553. /// </para>
  554. /// </remarks>
  555. /// <param name="buffer">The serialized script as an ArrayBuffer (preferably ExternalArrayBuffer).</param>
  556. /// <param name="scriptLoadCallback">
  557. /// Callback called when the source code of the script needs to be loaded.
  558. /// This is an optional parameter, set to null if not needed.
  559. /// </param>
  560. /// <param name="sourceContext">
  561. /// A cookie identifying the script that can be used by debuggable script contexts.
  562. /// This context will passed into scriptLoadCallback.
  563. /// </param>
  564. /// <param name="sourceUrl">The location the script came from.</param>
  565. /// <param name="result">A function representing the script code.</param>
  566. /// <returns>
  567. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  568. /// </returns>
  569. CHAKRA_API
  570. JsParseSerialized(
  571. _In_ JsValueRef buffer,
  572. _In_ JsSerializedLoadScriptCallback scriptLoadCallback,
  573. _In_ JsSourceContext sourceContext,
  574. _In_ JsValueRef sourceUrl,
  575. _Out_ JsValueRef *result);
  576. /// <summary>
  577. /// Runs a serialized script.
  578. /// Provides the ability to lazy load the script source only if/when it is needed.
  579. /// </summary>
  580. /// <remarks>
  581. /// <para>
  582. /// Requires an active script context.
  583. /// </para>
  584. /// <para>
  585. /// The runtime will detach the data from the buffer and hold on to it until all
  586. /// instances of any functions created from the buffer are garbage collected.
  587. /// </para>
  588. /// </remarks>
  589. /// <param name="buffer">The serialized script as an ArrayBuffer (preferably ExternalArrayBuffer).</param>
  590. /// <param name="scriptLoadCallback">Callback called when the source code of the script needs to be loaded.</param>
  591. /// <param name="sourceContext">
  592. /// A cookie identifying the script that can be used by debuggable script contexts.
  593. /// This context will passed into scriptLoadCallback.
  594. /// </param>
  595. /// <param name="sourceUrl">The location the script came from.</param>
  596. /// <param name="result">
  597. /// The result of running the script, if any. This parameter can be null.
  598. /// </param>
  599. /// <returns>
  600. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  601. /// </returns>
  602. CHAKRA_API
  603. JsRunSerialized(
  604. _In_ JsValueRef buffer,
  605. _In_ JsSerializedLoadScriptCallback scriptLoadCallback,
  606. _In_ JsSourceContext sourceContext,
  607. _In_ JsValueRef sourceUrl,
  608. _Out_ JsValueRef *result);
  609. /// <summary>
  610. /// Gets the state of a given Promise object.
  611. /// </summary>
  612. /// <remarks>
  613. /// Requires an active script context.
  614. /// </remarks>
  615. /// <param name="promise">The Promise object.</param>
  616. /// <param name="state">The current state of the Promise.</param>
  617. /// <returns>
  618. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  619. /// </returns>
  620. CHAKRA_API
  621. JsGetPromiseState(
  622. _In_ JsValueRef promise,
  623. _Out_ JsPromiseState *state);
  624. /// <summary>
  625. /// Gets the result of a given Promise object.
  626. /// </summary>
  627. /// <remarks>
  628. /// Requires an active script context.
  629. /// </remarks>
  630. /// <param name="promise">The Promise object.</param>
  631. /// <param name="result">The result of the Promise.</param>
  632. /// <returns>
  633. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  634. /// </returns>
  635. CHAKRA_API
  636. JsGetPromiseResult(
  637. _In_ JsValueRef promise,
  638. _Out_ JsValueRef *result);
  639. /// <summary>
  640. /// Creates a new JavaScript Promise object.
  641. /// </summary>
  642. /// <remarks>
  643. /// Requires an active script context.
  644. /// </remarks>
  645. /// <param name="promise">The new Promise object.</param>
  646. /// <param name="resolveFunction">The function called to resolve the created Promise object.</param>
  647. /// <param name="rejectFunction">The function called to reject the created Promise object.</param>
  648. /// <returns>
  649. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  650. /// </returns>
  651. CHAKRA_API
  652. JsCreatePromise(
  653. _Out_ JsValueRef *promise,
  654. _Out_ JsValueRef *resolveFunction,
  655. _Out_ JsValueRef *rejectFunction);
  656. /// <summary>
  657. /// A weak reference to a JavaScript value.
  658. /// </summary>
  659. /// <remarks>
  660. /// A value with only weak references is available for garbage-collection. A strong reference
  661. /// to the value (<c>JsValueRef</c>) may be obtained from a weak reference if the value happens
  662. /// to still be available.
  663. /// </remarks>
  664. typedef JsRef JsWeakRef;
  665. /// <summary>
  666. /// Creates a weak reference to a value.
  667. /// </summary>
  668. /// <param name="value">The value to be referenced.</param>
  669. /// <param name="weakRef">Weak reference to the value.</param>
  670. /// <returns>
  671. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  672. /// </returns>
  673. CHAKRA_API
  674. JsCreateWeakReference(
  675. _In_ JsValueRef value,
  676. _Out_ JsWeakRef* weakRef);
  677. /// <summary>
  678. /// Gets a strong reference to the value referred to by a weak reference.
  679. /// </summary>
  680. /// <param name="weakRef">A weak reference.</param>
  681. /// <param name="value">Reference to the value, or <c>JS_INVALID_REFERENCE</c> if the value is
  682. /// no longer available.</param>
  683. /// <returns>
  684. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  685. /// </returns>
  686. CHAKRA_API
  687. JsGetWeakReferenceValue(
  688. _In_ JsWeakRef weakRef,
  689. _Out_ JsValueRef* value);
  690. /// <summary>
  691. /// Creates a Javascript SharedArrayBuffer object with shared content get from JsGetSharedArrayBufferContent.
  692. /// </summary>
  693. /// <remarks>
  694. /// Requires an active script context.
  695. /// </remarks>
  696. /// <param name="sharedContents">
  697. /// The storage object of a SharedArrayBuffer which can be shared between multiple thread.
  698. /// </param>
  699. /// <param name="result">The new SharedArrayBuffer object.</param>
  700. /// <returns>
  701. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  702. /// </returns>
  703. CHAKRA_API
  704. JsCreateSharedArrayBufferWithSharedContent(
  705. _In_ JsSharedArrayBufferContentHandle sharedContents,
  706. _Out_ JsValueRef *result);
  707. /// <summary>
  708. /// Get the storage object from a SharedArrayBuffer.
  709. /// </summary>
  710. /// <remarks>
  711. /// Requires an active script context.
  712. /// </remarks>
  713. /// <param name="sharedArrayBuffer">The SharedArrayBuffer object.</param>
  714. /// <param name="sharedContents">
  715. /// The storage object of a SharedArrayBuffer which can be shared between multiple thread.
  716. /// User should call JsReleaseSharedArrayBufferContentHandle after finished using it.
  717. /// </param>
  718. /// <returns>
  719. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  720. /// </returns>
  721. CHAKRA_API
  722. JsGetSharedArrayBufferContent(
  723. _In_ JsValueRef sharedArrayBuffer,
  724. _Out_ JsSharedArrayBufferContentHandle *sharedContents);
  725. /// <summary>
  726. /// Decrease the reference count on a SharedArrayBuffer storage object.
  727. /// </summary>
  728. /// <remarks>
  729. /// Requires an active script context.
  730. /// </remarks>
  731. /// <param name="sharedContents">
  732. /// The storage object of a SharedArrayBuffer which can be shared between multiple thread.
  733. /// </param>
  734. /// <returns>
  735. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  736. /// </returns>
  737. CHAKRA_API
  738. JsReleaseSharedArrayBufferContentHandle(
  739. _In_ JsSharedArrayBufferContentHandle sharedContents);
  740. /// <summary>
  741. /// Determines whether an object has a non-inherited property.
  742. /// </summary>
  743. /// <remarks>
  744. /// Requires an active script context.
  745. /// </remarks>
  746. /// <param name="object">The object that may contain the property.</param>
  747. /// <param name="propertyId">The ID of the property.</param>
  748. /// <param name="hasOwnProperty">Whether the object has the non-inherited property.</param>
  749. /// <returns>
  750. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  751. /// </returns>
  752. CHAKRA_API
  753. JsHasOwnProperty(
  754. _In_ JsValueRef object,
  755. _In_ JsPropertyIdRef propertyId,
  756. _Out_ bool *hasOwnProperty);
  757. /// <summary>
  758. /// Write JS string value into char string buffer without a null terminator
  759. /// </summary>
  760. /// <remarks>
  761. /// <para>
  762. /// When size of the `buffer` is unknown,
  763. /// `buffer` argument can be nullptr.
  764. /// In that case, `written` argument will return the length needed.
  765. /// </para>
  766. /// <para>
  767. /// When start is out of range or &lt; 0, returns JsErrorInvalidArgument
  768. /// and `written` will be equal to 0.
  769. /// If calculated length is 0 (It can be due to string length or `start`
  770. /// and length combination), then `written` will be equal to 0 and call
  771. /// returns JsNoError
  772. /// </para>
  773. /// <para>
  774. /// The JS string `value` will be converted one utf16 code point at a time,
  775. /// and if it has code points that do not fit in one byte, those values
  776. /// will be truncated.
  777. /// </para>
  778. /// </remarks>
  779. /// <param name="value">JavascriptString value</param>
  780. /// <param name="start">Start offset of buffer</param>
  781. /// <param name="length">Number of characters to be written</param>
  782. /// <param name="buffer">Pointer to buffer</param>
  783. /// <param name="written">Total number of characters written</param>
  784. /// <returns>
  785. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  786. /// </returns>
  787. CHAKRA_API
  788. JsCopyStringOneByte(
  789. _In_ JsValueRef value,
  790. _In_ int start,
  791. _In_ int length,
  792. _Out_opt_ char* buffer,
  793. _Out_opt_ size_t* written);
  794. /// <summary>
  795. /// Obtains frequently used properties of a data view.
  796. /// </summary>
  797. /// <param name="dataView">The data view instance.</param>
  798. /// <param name="arrayBuffer">The ArrayBuffer backstore of the view.</param>
  799. /// <param name="byteOffset">The offset in bytes from the start of arrayBuffer referenced by the array.</param>
  800. /// <param name="byteLength">The number of bytes in the array.</param>
  801. /// <returns>
  802. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  803. /// </returns>
  804. CHAKRA_API
  805. JsGetDataViewInfo(
  806. _In_ JsValueRef dataView,
  807. _Out_opt_ JsValueRef *arrayBuffer,
  808. _Out_opt_ unsigned int *byteOffset,
  809. _Out_opt_ unsigned int *byteLength);
  810. /// <summary>
  811. /// Determine if one JavaScript value is less than another JavaScript value.
  812. /// </summary>
  813. /// <remarks>
  814. /// <para>
  815. /// This function is equivalent to the <c>&lt;</c> operator in Javascript.
  816. /// </para>
  817. /// <para>
  818. /// Requires an active script context.
  819. /// </para>
  820. /// </remarks>
  821. /// <param name="object1">The first object to compare.</param>
  822. /// <param name="object2">The second object to compare.</param>
  823. /// <param name="result">Whether object1 is less than object2.</param>
  824. /// <returns>
  825. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  826. /// </returns>
  827. CHAKRA_API
  828. JsLessThan(
  829. _In_ JsValueRef object1,
  830. _In_ JsValueRef object2,
  831. _Out_ bool *result);
  832. /// <summary>
  833. /// Determine if one JavaScript value is less than or equal to another JavaScript value.
  834. /// </summary>
  835. /// <remarks>
  836. /// <para>
  837. /// This function is equivalent to the <c>&lt;=</c> operator in Javascript.
  838. /// </para>
  839. /// <para>
  840. /// Requires an active script context.
  841. /// </para>
  842. /// </remarks>
  843. /// <param name="object1">The first object to compare.</param>
  844. /// <param name="object2">The second object to compare.</param>
  845. /// <param name="result">Whether object1 is less than or equal to object2.</param>
  846. /// <returns>
  847. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  848. /// </returns>
  849. CHAKRA_API
  850. JsLessThanOrEqual(
  851. _In_ JsValueRef object1,
  852. _In_ JsValueRef object2,
  853. _Out_ bool *result);
  854. /// <summary>
  855. /// Creates a new object (with prototype) that stores some external data.
  856. /// </summary>
  857. /// <remarks>
  858. /// Requires an active script context.
  859. /// </remarks>
  860. /// <param name="data">External data that the object will represent. May be null.</param>
  861. /// <param name="finalizeCallback">
  862. /// A callback for when the object is finalized. May be null.
  863. /// </param>
  864. /// <param name="prototype">Prototype object or nullptr.</param>
  865. /// <param name="object">The new object.</param>
  866. /// <returns>
  867. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  868. /// </returns>
  869. CHAKRA_API
  870. JsCreateExternalObjectWithPrototype(
  871. _In_opt_ void *data,
  872. _In_opt_ JsFinalizeCallback finalizeCallback,
  873. _In_opt_ JsValueRef prototype,
  874. _Out_ JsValueRef *object);
  875. /// <summary>
  876. /// Gets an object's property.
  877. /// </summary>
  878. /// <remarks>
  879. /// Requires an active script context.
  880. /// </remarks>
  881. /// <param name="object">The object that contains the property.</param>
  882. /// <param name="key">The key (JavascriptString or JavascriptSymbol) to the property.</param>
  883. /// <param name="value">The value of the property.</param>
  884. /// <returns>
  885. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  886. /// </returns>
  887. CHAKRA_API
  888. JsObjectGetProperty(
  889. _In_ JsValueRef object,
  890. _In_ JsValueRef key,
  891. _Out_ JsValueRef *value);
  892. /// <summary>
  893. /// Puts an object's property.
  894. /// </summary>
  895. /// <remarks>
  896. /// Requires an active script context.
  897. /// </remarks>
  898. /// <param name="object">The object that contains the property.</param>
  899. /// <param name="key">The key (JavascriptString or JavascriptSymbol) to the property.</param>
  900. /// <param name="value">The new value of the property.</param>
  901. /// <param name="useStrictRules">The property set should follow strict mode rules.</param>
  902. /// <returns>
  903. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  904. /// </returns>
  905. CHAKRA_API
  906. JsObjectSetProperty(
  907. _In_ JsValueRef object,
  908. _In_ JsValueRef key,
  909. _In_ JsValueRef value,
  910. _In_ bool useStrictRules);
  911. /// <summary>
  912. /// Determines whether an object has a property.
  913. /// </summary>
  914. /// <remarks>
  915. /// Requires an active script context.
  916. /// </remarks>
  917. /// <param name="object">The object that may contain the property.</param>
  918. /// <param name="key">The key (JavascriptString or JavascriptSymbol) to the property.</param>
  919. /// <param name="hasProperty">Whether the object (or a prototype) has the property.</param>
  920. /// <returns>
  921. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  922. /// </returns>
  923. CHAKRA_API
  924. JsObjectHasProperty(
  925. _In_ JsValueRef object,
  926. _In_ JsValueRef key,
  927. _Out_ bool *hasProperty);
  928. /// <summary>
  929. /// Defines a new object's own property from a property descriptor.
  930. /// </summary>
  931. /// <remarks>
  932. /// Requires an active script context.
  933. /// </remarks>
  934. /// <param name="object">The object that has the property.</param>
  935. /// <param name="key">The key (JavascriptString or JavascriptSymbol) to the property.</param>
  936. /// <param name="propertyDescriptor">The property descriptor.</param>
  937. /// <param name="result">Whether the property was defined.</param>
  938. /// <returns>
  939. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  940. /// </returns>
  941. CHAKRA_API
  942. JsObjectDefineProperty(
  943. _In_ JsValueRef object,
  944. _In_ JsValueRef key,
  945. _In_ JsValueRef propertyDescriptor,
  946. _Out_ bool *result);
  947. /// <summary>
  948. /// Deletes an object's property.
  949. /// </summary>
  950. /// <remarks>
  951. /// Requires an active script context.
  952. /// </remarks>
  953. /// <param name="object">The object that contains the property.</param>
  954. /// <param name="key">The key (JavascriptString or JavascriptSymbol) to the property.</param>
  955. /// <param name="useStrictRules">The property set should follow strict mode rules.</param>
  956. /// <param name="result">Whether the property was deleted.</param>
  957. /// <returns>
  958. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  959. /// </returns>
  960. CHAKRA_API
  961. JsObjectDeleteProperty(
  962. _In_ JsValueRef object,
  963. _In_ JsValueRef key,
  964. _In_ bool useStrictRules,
  965. _Out_ JsValueRef *result);
  966. /// <summary>
  967. /// Gets a property descriptor for an object's own property.
  968. /// </summary>
  969. /// <remarks>
  970. /// Requires an active script context.
  971. /// </remarks>
  972. /// <param name="object">The object that has the property.</param>
  973. /// <param name="key">The key (JavascriptString or JavascriptSymbol) to the property.</param>
  974. /// <param name="propertyDescriptor">The property descriptor.</param>
  975. /// <returns>
  976. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  977. /// </returns>
  978. CHAKRA_API
  979. JsObjectGetOwnPropertyDescriptor(
  980. _In_ JsValueRef object,
  981. _In_ JsValueRef key,
  982. _Out_ JsValueRef *propertyDescriptor);
  983. /// <summary>
  984. /// Determines whether an object has a non-inherited property.
  985. /// </summary>
  986. /// <remarks>
  987. /// Requires an active script context.
  988. /// </remarks>
  989. /// <param name="object">The object that may contain the property.</param>
  990. /// <param name="key">The key (JavascriptString or JavascriptSymbol) to the property.</param>
  991. /// <param name="hasOwnProperty">Whether the object has the non-inherited property.</param>
  992. /// <returns>
  993. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  994. /// </returns>
  995. CHAKRA_API
  996. JsObjectHasOwnProperty(
  997. _In_ JsValueRef object,
  998. _In_ JsValueRef key,
  999. _Out_ bool *hasOwnProperty);
  1000. /// <summary>
  1001. /// Sets whether any action should be taken when a promise is rejected with no reactions
  1002. /// or a reaction is added to a promise that was rejected before it had reactions.
  1003. /// By default in either of these cases nothing occurs.
  1004. /// This function allows you to specify if something should occur and provide a callback
  1005. /// to implement whatever should occur.
  1006. /// </summary>
  1007. /// <remarks>
  1008. /// Requires an active script context.
  1009. /// </remarks>
  1010. /// <param name="promiseRejectionTrackerCallback">The callback function being set.</param>
  1011. /// <param name="callbackState">
  1012. /// User provided state that will be passed back to the callback.
  1013. /// </param>
  1014. /// <returns>
  1015. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1016. /// </returns>
  1017. CHAKRA_API
  1018. JsSetHostPromiseRejectionTracker(
  1019. _In_ JsHostPromiseRejectionTrackerCallback promiseRejectionTrackerCallback,
  1020. _In_opt_ void *callbackState);
  1021. /// <summary>
  1022. /// Determines if a provided object is a JavscriptProxy Object and
  1023. /// provides references to a Proxy's target and handler.
  1024. /// </summary>
  1025. /// <remarks>
  1026. /// Requires an active script context.
  1027. /// If object is not a Proxy object the target and handler parameters are not touched.
  1028. /// If nullptr is supplied for target or handler the function returns after
  1029. /// setting the isProxy value.
  1030. /// If the object is a revoked Proxy target and handler are set to JS_INVALID_REFERENCE.
  1031. /// If it is a Proxy object that has not been revoked target and handler are set to the
  1032. /// the object's target and handler.
  1033. /// </remarks>
  1034. /// <param name="object">The object that may be a Proxy.</param>
  1035. /// <param name="isProxy">Pointer to a Boolean - is the object a proxy?</param>
  1036. /// <param name="target">Pointer to a JsValueRef - the object's target.</param>
  1037. /// <param name="handler">Pointer to a JsValueRef - the object's handler.</param>
  1038. /// <returns>
  1039. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  1040. /// </returns>
  1041. CHAKRA_API
  1042. JsGetProxyProperties(
  1043. _In_ JsValueRef object,
  1044. _Out_ bool* isProxy,
  1045. _Out_opt_ JsValueRef* target,
  1046. _Out_opt_ JsValueRef* handler);
  1047. #endif // _CHAKRACOREBUILD
  1048. #endif // _CHAKRACORE_H_