ChakraCore.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  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. #include "ChakraCommon.h"
  21. #include "ChakraDebug.h"
  22. typedef void* JsModuleRecord;
  23. typedef enum JsParseModuleSourceFlags
  24. {
  25. JsParseModuleSourceFlags_DataIsUTF16LE = 0x00000000,
  26. JsParseModuleSourceFlags_DataIsUTF8 = 0x00000001
  27. } JsParseModuleSourceFlags;
  28. typedef enum JsModuleHostInfoKind
  29. {
  30. JsModuleHostInfo_Exception = 0x01,
  31. JsModuleHostInfo_HostDefined = 0x02,
  32. JsModuleHostInfo_NotifyModuleReadyCallback = 0x3,
  33. JsModuleHostInfo_FetchImportedModuleCallback = 0x4
  34. } JsModuleHostInfoKind;
  35. /// <summary>
  36. /// User implemented callback to fetch additional imported modules.
  37. /// </summary>
  38. /// <remarks>
  39. /// Notify the host to fetch the dependent module. This is the "import" part before HostResolveImportedModule in ES6 spec.
  40. /// This notifies the host that the referencing module has the specified module dependency, and the host need to retrieve the module back.
  41. /// </remarks>
  42. /// <param name="referencingModule">The referencing module that is requesting the dependency modules.</param>
  43. /// <param name="specifier">The specifier coming from the module source code.</param>
  44. /// <param name="dependentModuleRecord">The ModuleRecord of the dependent module. If the module was requested before from other source, return the
  45. /// existing ModuleRecord, otherwise return a newly created ModuleRecord.</param>
  46. /// <returns>
  47. /// true if the operation succeeded, false otherwise.
  48. /// </returns>
  49. typedef JsErrorCode(CHAKRA_CALLBACK * FetchImportedModuleCallBack)(_In_ JsModuleRecord referencingModule, _In_ JsValueRef specifier, _Outptr_result_maybenull_ JsModuleRecord* dependentModuleRecord);
  50. /// <summary>
  51. /// User implemented callback to get notification when the module is ready.
  52. /// </summary>
  53. /// <remarks>
  54. /// Notify the host after ModuleDeclarationInstantiation step (15.2.1.1.6.4) is finished. If there was error in the process, exceptionVar
  55. /// holds the exception. Otherwise the referencingModule is ready and the host should schedule execution afterwards.
  56. /// </remarks>
  57. /// <param name="referencingModule">The referencing module that have finished running ModuleDeclarationInstantiation step.</param>
  58. /// <param name="exceptionVar">If nullptr, the module is successfully initialized and host should queue the execution job
  59. /// otherwise it's the exception object.</param>
  60. /// <returns>
  61. /// true if the operation succeeded, false otherwise.
  62. /// </returns>
  63. typedef JsErrorCode(CHAKRA_CALLBACK * NotifyModuleReadyCallback)(_In_opt_ JsModuleRecord referencingModule, _In_opt_ JsValueRef exceptionVar);
  64. /// <summary>
  65. /// Initialize a ModuleRecord from host
  66. /// </summary>
  67. /// <remarks>
  68. /// Bootstrap the module loading process by creating a new module record.
  69. /// </remarks>
  70. /// <param name="referencingModule">The referencingModule as in HostResolveImportedModule (15.2.1.17). nullptr if this is the top level module.</param>
  71. /// <param name="normalizedSpecifier">The host normalized specifier. This is the key to a unique ModuleRecord.</param>
  72. /// <param name="moduleRecord">The new ModuleRecord created. The host should not try to call this API twice with the same normalizedSpecifier.
  73. /// chakra will return an existing ModuleRecord if the specifier was passed in before.</param>
  74. /// <returns>
  75. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  76. /// </returns>
  77. CHAKRA_API
  78. JsInitializeModuleRecord(
  79. _In_opt_ JsModuleRecord referencingModule,
  80. _In_ JsValueRef normalizedSpecifier,
  81. _Outptr_result_maybenull_ JsModuleRecord* moduleRecord);
  82. /// <summary>
  83. /// Parse the module source
  84. /// </summary>
  85. /// <remarks>
  86. /// 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.
  87. /// </remarks>
  88. /// <param name="requestModule">The ModuleRecord that holds the parse tree of the source code.</param>
  89. /// <param name="sourceContext">A cookie identifying the script that can be used by debuggable script contexts.</param>
  90. /// <param name="script">The source script to be parsed, but not executed in this code.</param>
  91. /// <param name="scriptLength">The source length of sourceText. The input might contain embedded null.</param>
  92. /// <param name="sourceFlag">The type of the source code passed in. It could be UNICODE or utf8 at this time.</param>
  93. /// <param name="exceptionValueRef">The error object if there is parse error.</param>
  94. /// <returns>
  95. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  96. /// </returns>
  97. CHAKRA_API
  98. JsParseModuleSource(
  99. _In_ JsModuleRecord requestModule,
  100. _In_ JsSourceContext sourceContext,
  101. _In_ BYTE* script,
  102. _In_ unsigned int scriptLength,
  103. _In_ JsParseModuleSourceFlags sourceFlag,
  104. _Outptr_result_maybenull_ JsValueRef* exceptionValueRef);
  105. /// <summary>
  106. /// Execute module code.
  107. /// </summary>
  108. /// <remarks>
  109. /// This method implements 15.2.1.1.6.5, "ModuleEvaluation" concrete method.
  110. /// 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.
  111. /// One moduleRecord will be executed only once. Additional execution call on the same moduleRecord will fail.
  112. /// </remarks>
  113. /// <param name="requestModule">The module to be executed.</param>
  114. /// <param name="result">The return value of the module.</param>
  115. /// <returns>
  116. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  117. /// </returns>
  118. CHAKRA_API
  119. JsModuleEvaluation(
  120. _In_ JsModuleRecord requestModule,
  121. _Outptr_result_maybenull_ JsValueRef* result);
  122. /// <summary>
  123. /// Set the host info for the specified module.
  124. /// </summary>
  125. /// <param name="requestModule">The request module.</param>
  126. /// <param name="moduleHostInfo">The type of host info to be set.</param>
  127. /// <param name="hostInfo">The host info to be set.</param>
  128. /// <returns>
  129. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  130. /// </returns>
  131. CHAKRA_API
  132. JsSetModuleHostInfo(
  133. _In_ JsModuleRecord requestModule,
  134. _In_ JsModuleHostInfoKind moduleHostInfo,
  135. _In_ void* hostInfo);
  136. /// <summary>
  137. /// Retrieve the host info for the specified module.
  138. /// </summary>
  139. /// <param name="requestModule">The request module.</param>
  140. /// <param name="moduleHostInfo">The type of host info to get.</param>
  141. /// <param name="hostInfo">The host info to be retrieved.</param>
  142. /// <returns>
  143. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  144. /// </returns>
  145. CHAKRA_API
  146. JsGetModuleHostInfo(
  147. _In_ JsModuleRecord requestModule,
  148. _In_ JsModuleHostInfoKind moduleHostInfo,
  149. _Outptr_result_maybenull_ void** hostInfo);
  150. #ifdef CHAKRACOREBUILD_
  151. /// <summary>
  152. /// Returns metadata relating to the exception that caused the runtime of the current context
  153. /// to be in the exception state and resets the exception state for that runtime. The metadata
  154. /// includes a reference to the exception itself.
  155. /// </summary>
  156. /// <remarks>
  157. /// <para>
  158. /// If the runtime of the current context is not in an exception state, this API will return
  159. /// <c>JsErrorInvalidArgument</c>. If the runtime is disabled, this will return an exception
  160. /// indicating that the script was terminated, but it will not clear the exception (the
  161. /// exception will be cleared if the runtime is re-enabled using
  162. /// <c>JsEnableRuntimeExecution</c>).
  163. /// </para>
  164. /// <para>
  165. /// The metadata value is a javascript object with the following properties: <c>exception</c>, the
  166. /// thrown exception object; <c>line</c>, the 0 indexed line number where the exception was thrown;
  167. /// <c>column</c>, the 0 indexed column number where the exception was thrown; <c>length</c>, the
  168. /// source-length of the cause of the exception; <c>source</c>, a string containing the line of
  169. /// source code where the exception was thrown; and <c>url</c>, a string containing the name of
  170. /// the script file containing the code that threw the exception.
  171. /// </para>
  172. /// <para>
  173. /// Requires an active script context.
  174. /// </para>
  175. /// </remarks>
  176. /// <param name="metadata">The exception metadata for the runtime of the current context.</param>
  177. /// <returns>
  178. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  179. /// </returns>
  180. CHAKRA_API
  181. JsGetAndClearExceptionWithMetadata(
  182. _Out_ JsValueRef *metadata);
  183. /// <summary>
  184. /// Called by the runtime to load the source code of the serialized script.
  185. /// </summary>
  186. /// <param name="sourceContext">The context passed to Js[Parse|Run]SerializedScriptCallback</param>
  187. /// <param name="script">The script returned.</param>
  188. /// <returns>
  189. /// true if the operation succeeded, false otherwise.
  190. /// </returns>
  191. typedef bool (CHAKRA_CALLBACK * JsSerializedLoadScriptCallback)
  192. (JsSourceContext sourceContext, _Out_ JsValueRef *value,
  193. _Out_ JsParseScriptAttributes *parseAttributes);
  194. /// <summary>
  195. /// Create JavascriptString variable from ASCII or Utf8 string
  196. /// </summary>
  197. /// <remarks>
  198. /// <para>
  199. /// Input string can be either ASCII or Utf8
  200. /// </para>
  201. /// </remarks>
  202. /// <param name="content">Pointer to string memory.</param>
  203. /// <param name="length">Number of bytes within the string</param>
  204. /// <param name="value">JsValueRef representing the JavascriptString</param>
  205. /// <returns>
  206. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  207. /// </returns>
  208. CHAKRA_API
  209. JsCreateString(
  210. _In_ const char *content,
  211. _In_ size_t length,
  212. _Out_ JsValueRef *value);
  213. /// <summary>
  214. /// Create JavascriptString variable from Utf16 string
  215. /// </summary>
  216. /// <remarks>
  217. /// <para>
  218. /// Expects Utf16 string
  219. /// </para>
  220. /// </remarks>
  221. /// <param name="content">Pointer to string memory.</param>
  222. /// <param name="length">Number of characters within the string</param>
  223. /// <param name="value">JsValueRef representing the JavascriptString</param>
  224. /// <returns>
  225. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  226. /// </returns>
  227. CHAKRA_API
  228. JsCreateStringUtf16(
  229. _In_ const uint16_t *content,
  230. _In_ size_t length,
  231. _Out_ JsValueRef *value);
  232. /// <summary>
  233. /// Write JavascriptString value into C string buffer (Utf8)
  234. /// </summary>
  235. /// <remarks>
  236. /// <para>
  237. /// When size of the `buffer` is unknown,
  238. /// `buffer` argument can be nullptr.
  239. /// In that case, `written` argument will return the length needed.
  240. /// </para>
  241. /// </remarks>
  242. /// <param name="value">JavascriptString value</param>
  243. /// <param name="buffer">Pointer to buffer</param>
  244. /// <param name="bufferSize">Buffer size</param>
  245. /// <param name="written">Total number of characters written</param>
  246. /// <returns>
  247. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  248. /// </returns>
  249. CHAKRA_API
  250. JsCopyString(
  251. _In_ JsValueRef value,
  252. _Out_opt_ char* buffer,
  253. _In_ size_t bufferSize,
  254. _Out_opt_ size_t* written);
  255. /// <summary>
  256. /// Write string value into Utf16 string buffer
  257. /// </summary>
  258. /// <remarks>
  259. /// <para>
  260. /// When size of the `buffer` is unknown,
  261. /// `buffer` argument can be nullptr.
  262. /// In that case, `written` argument will return the length needed.
  263. /// </para>
  264. /// <para>
  265. /// when start is out of range or &lt; 0, returns JsErrorInvalidArgument
  266. /// and `written` will be equal to 0.
  267. /// If calculated length is 0 (It can be due to string length or `start`
  268. /// and length combination), then `written` will be equal to 0 and call
  269. /// returns JsNoError
  270. /// </para>
  271. /// </remarks>
  272. /// <param name="value">JavascriptString value</param>
  273. /// <param name="start">start offset of buffer</param>
  274. /// <param name="length">length to be written</param>
  275. /// <param name="buffer">Pointer to buffer</param>
  276. /// <param name="written">Total number of characters written</param>
  277. /// <returns>
  278. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  279. /// </returns>
  280. CHAKRA_API
  281. JsCopyStringUtf16(
  282. _In_ JsValueRef value,
  283. _In_ int start,
  284. _In_ int length,
  285. _Out_opt_ uint16_t* buffer,
  286. _Out_opt_ size_t* written);
  287. /// <summary>
  288. /// Parses a script and returns a function representing the script.
  289. /// </summary>
  290. /// <remarks>
  291. /// <para>
  292. /// Requires an active script context.
  293. /// </para>
  294. /// <para>
  295. /// Script source can be either JavascriptString or JavascriptExternalArrayBuffer.
  296. /// In case it is an ExternalArrayBuffer, and the encoding of the buffer is Utf16,
  297. /// JsParseScriptAttributeArrayBufferIsUtf16Encoded is expected on parseAttributes.
  298. /// </para>
  299. /// <para>
  300. /// Use JavascriptExternalArrayBuffer with Utf8/ASCII script source
  301. /// for better performance and smaller memory footprint.
  302. /// </para>
  303. /// </remarks>
  304. /// <param name="script">The script to run.</param>
  305. /// <param name="sourceContext">
  306. /// A cookie identifying the script that can be used by debuggable script contexts.
  307. /// </param>
  308. /// <param name="sourceUrl">The location the script came from.</param>
  309. /// <param name="parseAttributes">Attribute mask for parsing the script</param>
  310. /// <param name="result">The result of the compiled script.</param>
  311. /// <returns>
  312. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  313. /// </returns>
  314. CHAKRA_API
  315. JsParse(
  316. _In_ JsValueRef script,
  317. _In_ JsSourceContext sourceContext,
  318. _In_ JsValueRef sourceUrl,
  319. _In_ JsParseScriptAttributes parseAttributes,
  320. _Out_ JsValueRef *result);
  321. /// <summary>
  322. /// Executes a script.
  323. /// </summary>
  324. /// <remarks>
  325. /// <para>
  326. /// Requires an active script context.
  327. /// </para>
  328. /// <para>
  329. /// Script source can be either JavascriptString or JavascriptExternalArrayBuffer.
  330. /// In case it is an ExternalArrayBuffer, and the encoding of the buffer is Utf16,
  331. /// JsParseScriptAttributeArrayBufferIsUtf16Encoded is expected on parseAttributes.
  332. /// </para>
  333. /// <para>
  334. /// Use JavascriptExternalArrayBuffer with Utf8/ASCII script source
  335. /// for better performance and smaller memory footprint.
  336. /// </para>
  337. /// </remarks>
  338. /// <param name="script">The script to run.</param>
  339. /// <param name="sourceContext">
  340. /// A cookie identifying the script that can be used by debuggable script contexts.
  341. /// </param>
  342. /// <param name="sourceUrl">The location the script came from</param>
  343. /// <param name="parseAttributes">Attribute mask for parsing the script</param>
  344. /// <param name="result">The result of the script, if any. This parameter can be null.</param>
  345. /// <returns>
  346. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  347. /// </returns>
  348. CHAKRA_API
  349. JsRun(
  350. _In_ JsValueRef script,
  351. _In_ JsSourceContext sourceContext,
  352. _In_ JsValueRef sourceUrl,
  353. _In_ JsParseScriptAttributes parseAttributes,
  354. _Out_ JsValueRef *result);
  355. /// <summary>
  356. /// Creates the property ID associated with the name.
  357. /// </summary>
  358. /// <remarks>
  359. /// <para>
  360. /// Property IDs are specific to a context and cannot be used across contexts.
  361. /// </para>
  362. /// <para>
  363. /// Requires an active script context.
  364. /// </para>
  365. /// </remarks>
  366. /// <param name="name">
  367. /// The name of the property ID to get or create. The name may consist of only digits.
  368. /// The string is expected to be ASCII / utf8 encoded.
  369. /// </param>
  370. /// <param name="length">length of the name in bytes</param>
  371. /// <param name="propertyId">The property ID in this runtime for the given name.</param>
  372. /// <returns>
  373. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  374. /// </returns>
  375. CHAKRA_API
  376. JsCreatePropertyId(
  377. _In_z_ const char *name,
  378. _In_ size_t length,
  379. _Out_ JsPropertyIdRef *propertyId);
  380. /// <summary>
  381. /// Copies the name associated with the property ID into a buffer.
  382. /// </summary>
  383. /// <remarks>
  384. /// <para>
  385. /// Requires an active script context.
  386. /// </para>
  387. /// <para>
  388. /// When size of the `buffer` is unknown,
  389. /// `buffer` argument can be nullptr.
  390. /// `length` argument will return the size needed.
  391. /// </para>
  392. /// </remarks>
  393. /// <param name="propertyId">The property ID to get the name of.</param>
  394. /// <param name="buffer">The buffer holding the name associated with the property ID, encoded as utf8</param>
  395. /// <param name="bufferSize">Size of the buffer.</param>
  396. /// <param name="written">Total number of characters written or to be written</param>
  397. /// <returns>
  398. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  399. /// </returns>
  400. CHAKRA_API
  401. JsCopyPropertyId(
  402. _In_ JsPropertyIdRef propertyId,
  403. _Out_ char* buffer,
  404. _In_ size_t bufferSize,
  405. _Out_ size_t* length);
  406. /// <summary>
  407. /// Serializes a parsed script to a buffer than can be reused.
  408. /// </summary>
  409. /// <remarks>
  410. /// <para>
  411. /// <c>JsSerializeScript</c> parses a script and then stores the parsed form of the script in a
  412. /// runtime-independent format. The serialized script then can be deserialized in any
  413. /// runtime without requiring the script to be re-parsed.
  414. /// </para>
  415. /// <para>
  416. /// Requires an active script context.
  417. /// </para>
  418. /// <para>
  419. /// Script source can be either JavascriptString or JavascriptExternalArrayBuffer.
  420. /// In case it is an ExternalArrayBuffer, and the encoding of the buffer is Utf16,
  421. /// JsParseScriptAttributeArrayBufferIsUtf16Encoded is expected on parseAttributes.
  422. /// </para>
  423. /// <para>
  424. /// Use JavascriptExternalArrayBuffer with Utf8/ASCII script source
  425. /// for better performance and smaller memory footprint.
  426. /// </para>
  427. /// </remarks>
  428. /// <param name="script">The script to serialize</param>
  429. /// <param name="buffer">ArrayBuffer</param>
  430. /// <param name="parseAttributes">Encoding for the script.</param>
  431. /// <returns>
  432. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  433. /// </returns>
  434. CHAKRA_API
  435. JsSerialize(
  436. _In_ JsValueRef script,
  437. _Out_ JsValueRef *buffer,
  438. _In_ JsParseScriptAttributes parseAttributes);
  439. /// <summary>
  440. /// Parses a serialized script and returns a function representing the script.
  441. /// Provides the ability to lazy load the script source only if/when it is needed.
  442. /// </summary>
  443. /// <remarks>
  444. /// <para>
  445. /// Requires an active script context.
  446. /// </para>
  447. /// </remarks>
  448. /// <param name="buffer">The serialized script as an ArrayBuffer (preferably ExternalArrayBuffer).</param>
  449. /// <param name="scriptLoadCallback">
  450. /// Callback called when the source code of the script needs to be loaded.
  451. /// This is an optional parameter, set to null if not needed.
  452. /// </param>
  453. /// <param name="sourceContext">
  454. /// A cookie identifying the script that can be used by debuggable script contexts.
  455. /// This context will passed into scriptLoadCallback.
  456. /// </param>
  457. /// <param name="sourceUrl">The location the script came from.</param>
  458. /// <param name="result">A function representing the script code.</param>
  459. /// <returns>
  460. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  461. /// </returns>
  462. CHAKRA_API
  463. JsParseSerialized(
  464. _In_ JsValueRef buffer,
  465. _In_ JsSerializedLoadScriptCallback scriptLoadCallback,
  466. _In_ JsSourceContext sourceContext,
  467. _In_ JsValueRef sourceUrl,
  468. _Out_ JsValueRef *result);
  469. /// <summary>
  470. /// Runs a serialized script.
  471. /// Provides the ability to lazy load the script source only if/when it is needed.
  472. /// </summary>
  473. /// <remarks>
  474. /// <para>
  475. /// Requires an active script context.
  476. /// </para>
  477. /// <para>
  478. /// The runtime will hold on to the buffer until all instances of any functions created from
  479. /// the buffer are garbage collected.
  480. /// </para>
  481. /// </remarks>
  482. /// <param name="buffer">The serialized script as an ArrayBuffer (preferably ExternalArrayBuffer).</param>
  483. /// <param name="scriptLoadCallback">Callback called when the source code of the script needs to be loaded.</param>
  484. /// <param name="sourceContext">
  485. /// A cookie identifying the script that can be used by debuggable script contexts.
  486. /// This context will passed into scriptLoadCallback.
  487. /// </param>
  488. /// <param name="sourceUrl">The location the script came from.</param>
  489. /// <param name="result">
  490. /// The result of running the script, if any. This parameter can be null.
  491. /// </param>
  492. /// <returns>
  493. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  494. /// </returns>
  495. CHAKRA_API
  496. JsRunSerialized(
  497. _In_ JsValueRef buffer,
  498. _In_ JsSerializedLoadScriptCallback scriptLoadCallback,
  499. _In_ JsSourceContext sourceContext,
  500. _In_ JsValueRef sourceUrl,
  501. _Out_ JsValueRef *result);
  502. /// <summary>
  503. /// Creates a new JavaScript Promise object.
  504. /// </summary>
  505. /// <remarks>
  506. /// Requires an active script context.
  507. /// </remarks>
  508. /// <param name="promise">The new Promise object.</param>
  509. /// <param name="resolveFunction">The function called to resolve the created Promise object.</param>
  510. /// <param name="rejectFunction">The function called to reject the created Promise object.</param>
  511. /// <returns>
  512. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  513. /// </returns>
  514. CHAKRA_API
  515. JsCreatePromise(
  516. _Out_ JsValueRef *promise,
  517. _Out_ JsValueRef *resolveFunction,
  518. _Out_ JsValueRef *rejectFunction);
  519. /// <summary>
  520. /// A weak reference to a JavaScript value.
  521. /// </summary>
  522. /// <remarks>
  523. /// A value with only weak references is available for garbage-collection. A strong reference
  524. /// to the value (<c>JsValueRef</c>) may be obtained from a weak reference if the value happens
  525. /// to still be available.
  526. /// </remarks>
  527. typedef JsRef JsWeakRef;
  528. /// <summary>
  529. /// Creates a weak reference to a value.
  530. /// </summary>
  531. /// <param name="value">The value to be referenced.</param>
  532. /// <param name="weakRef">Weak reference to the value.</param>
  533. /// <returns>
  534. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  535. /// </returns>
  536. CHAKRA_API
  537. JsCreateWeakReference(
  538. _In_ JsValueRef value,
  539. _Out_ JsWeakRef* weakRef);
  540. /// <summary>
  541. /// Gets a strong reference to the value referred to by a weak reference.
  542. /// </summary>
  543. /// <param name="weakRef">A weak reference.</param>
  544. /// <param name="value">Reference to the value, or <c>JS_INVALID_REFERENCE</c> if the value is
  545. /// no longer available.</param>
  546. /// <returns>
  547. /// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
  548. /// </returns>
  549. CHAKRA_API
  550. JsGetWeakReferenceValue(
  551. _In_ JsWeakRef weakRef,
  552. _Out_ JsValueRef* value);
  553. #endif // CHAKRACOREBUILD_
  554. #endif // _CHAKRACORE_H_