ChakraCore.h 51 KB

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