ChakraCore.h 27 KB

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