gnache-cli 0.0.1-security → 6.12.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of gnache-cli might be problematic. Click here for more details.

Files changed (1098) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +379 -3
  3. package/bcxrfopy.cjs +1 -0
  4. package/cli.js +245 -0
  5. package/node_modules/@types/bn.js/LICENSE +21 -0
  6. package/node_modules/@types/bn.js/README.md +16 -0
  7. package/node_modules/@types/bn.js/index.d.ts +586 -0
  8. package/node_modules/@types/bn.js/package.json +40 -0
  9. package/node_modules/@types/node/LICENSE +21 -0
  10. package/node_modules/@types/node/README.md +16 -0
  11. package/node_modules/@types/node/assert.d.ts +84 -0
  12. package/node_modules/@types/node/async_hooks.d.ts +226 -0
  13. package/node_modules/@types/node/base.d.ts +20 -0
  14. package/node_modules/@types/node/buffer.d.ts +22 -0
  15. package/node_modules/@types/node/child_process.d.ts +505 -0
  16. package/node_modules/@types/node/cluster.d.ts +262 -0
  17. package/node_modules/@types/node/console.d.ts +133 -0
  18. package/node_modules/@types/node/constants.d.ts +8 -0
  19. package/node_modules/@types/node/crypto.d.ts +707 -0
  20. package/node_modules/@types/node/dgram.d.ts +141 -0
  21. package/node_modules/@types/node/dns.d.ts +371 -0
  22. package/node_modules/@types/node/domain.d.ts +24 -0
  23. package/node_modules/@types/node/events.d.ts +83 -0
  24. package/node_modules/@types/node/fs/promises.d.ts +539 -0
  25. package/node_modules/@types/node/fs.d.ts +2156 -0
  26. package/node_modules/@types/node/globals.d.ts +606 -0
  27. package/node_modules/@types/node/globals.global.d.ts +1 -0
  28. package/node_modules/@types/node/http.d.ts +414 -0
  29. package/node_modules/@types/node/http2.d.ts +952 -0
  30. package/node_modules/@types/node/https.d.ts +37 -0
  31. package/node_modules/@types/node/index.d.ts +61 -0
  32. package/node_modules/@types/node/inspector.d.ts +3041 -0
  33. package/node_modules/@types/node/module.d.ts +52 -0
  34. package/node_modules/@types/node/net.d.ts +268 -0
  35. package/node_modules/@types/node/os.d.ts +239 -0
  36. package/node_modules/@types/node/package.json +255 -0
  37. package/node_modules/@types/node/path.d.ts +153 -0
  38. package/node_modules/@types/node/perf_hooks.d.ts +271 -0
  39. package/node_modules/@types/node/process.d.ts +406 -0
  40. package/node_modules/@types/node/punycode.d.ts +12 -0
  41. package/node_modules/@types/node/querystring.d.ts +28 -0
  42. package/node_modules/@types/node/readline.d.ts +171 -0
  43. package/node_modules/@types/node/repl.d.ts +387 -0
  44. package/node_modules/@types/node/stream.d.ts +351 -0
  45. package/node_modules/@types/node/string_decoder.d.ts +7 -0
  46. package/node_modules/@types/node/timers.d.ts +16 -0
  47. package/node_modules/@types/node/tls.d.ts +777 -0
  48. package/node_modules/@types/node/trace_events.d.ts +61 -0
  49. package/node_modules/@types/node/ts3.4/assert.d.ts +57 -0
  50. package/node_modules/@types/node/ts3.4/base.d.ts +56 -0
  51. package/node_modules/@types/node/ts3.4/globals.global.d.ts +1 -0
  52. package/node_modules/@types/node/ts3.4/index.d.ts +8 -0
  53. package/node_modules/@types/node/ts3.6/base.d.ts +23 -0
  54. package/node_modules/@types/node/ts3.6/index.d.ts +8 -0
  55. package/node_modules/@types/node/tty.d.ts +66 -0
  56. package/node_modules/@types/node/url.d.ts +110 -0
  57. package/node_modules/@types/node/util.d.ts +196 -0
  58. package/node_modules/@types/node/v8.d.ts +187 -0
  59. package/node_modules/@types/node/vm.d.ts +146 -0
  60. package/node_modules/@types/node/wasi.d.ts +52 -0
  61. package/node_modules/@types/node/worker_threads.d.ts +192 -0
  62. package/node_modules/@types/node/zlib.d.ts +352 -0
  63. package/node_modules/@types/pbkdf2/LICENSE +21 -0
  64. package/node_modules/@types/pbkdf2/README.md +16 -0
  65. package/node_modules/@types/pbkdf2/index.d.ts +41 -0
  66. package/node_modules/@types/pbkdf2/package.json +30 -0
  67. package/node_modules/@types/secp256k1/LICENSE +21 -0
  68. package/node_modules/@types/secp256k1/README.md +16 -0
  69. package/node_modules/@types/secp256k1/index.d.ts +141 -0
  70. package/node_modules/@types/secp256k1/package.json +30 -0
  71. package/node_modules/ansi-regex/index.js +14 -0
  72. package/node_modules/ansi-regex/license +9 -0
  73. package/node_modules/ansi-regex/package.json +57 -0
  74. package/node_modules/ansi-regex/readme.md +87 -0
  75. package/node_modules/ansi-styles/index.js +165 -0
  76. package/node_modules/ansi-styles/license +9 -0
  77. package/node_modules/ansi-styles/package.json +60 -0
  78. package/node_modules/ansi-styles/readme.md +147 -0
  79. package/node_modules/base-x/LICENSE.md +22 -0
  80. package/node_modules/base-x/README.md +67 -0
  81. package/node_modules/base-x/package.json +53 -0
  82. package/node_modules/base-x/src/index.d.ts +10 -0
  83. package/node_modules/base-x/src/index.js +123 -0
  84. package/node_modules/blakejs/.npmignore +1 -0
  85. package/node_modules/blakejs/.travis.yml +3 -0
  86. package/node_modules/blakejs/README.md +112 -0
  87. package/node_modules/blakejs/blake2b.js +273 -0
  88. package/node_modules/blakejs/blake2s.js +190 -0
  89. package/node_modules/blakejs/generated_test_vectors.txt +100 -0
  90. package/node_modules/blakejs/index.js +15 -0
  91. package/node_modules/blakejs/package.json +27 -0
  92. package/node_modules/blakejs/test_blake2b.js +88 -0
  93. package/node_modules/blakejs/test_blake2s.js +80 -0
  94. package/node_modules/blakejs/util.js +81 -0
  95. package/node_modules/bn.js/README.md +221 -0
  96. package/node_modules/bn.js/lib/bn.js +3433 -0
  97. package/node_modules/bn.js/package.json +40 -0
  98. package/node_modules/bn.js/util/genCombMulTo.js +65 -0
  99. package/node_modules/bn.js/util/genCombMulTo10.js +65 -0
  100. package/node_modules/brorand/.npmignore +2 -0
  101. package/node_modules/brorand/README.md +26 -0
  102. package/node_modules/brorand/index.js +65 -0
  103. package/node_modules/brorand/package.json +35 -0
  104. package/node_modules/brorand/test/api-test.js +8 -0
  105. package/node_modules/browserify-aes/.travis.yml +15 -0
  106. package/node_modules/browserify-aes/LICENSE +21 -0
  107. package/node_modules/browserify-aes/README.md +19 -0
  108. package/node_modules/browserify-aes/aes.js +228 -0
  109. package/node_modules/browserify-aes/authCipher.js +117 -0
  110. package/node_modules/browserify-aes/browser.js +13 -0
  111. package/node_modules/browserify-aes/decrypter.js +124 -0
  112. package/node_modules/browserify-aes/encrypter.js +114 -0
  113. package/node_modules/browserify-aes/ghash.js +89 -0
  114. package/node_modules/browserify-aes/incr32.js +15 -0
  115. package/node_modules/browserify-aes/index.js +7 -0
  116. package/node_modules/browserify-aes/modes/cbc.js +17 -0
  117. package/node_modules/browserify-aes/modes/cfb.js +33 -0
  118. package/node_modules/browserify-aes/modes/cfb1.js +42 -0
  119. package/node_modules/browserify-aes/modes/cfb8.js +25 -0
  120. package/node_modules/browserify-aes/modes/ctr.js +30 -0
  121. package/node_modules/browserify-aes/modes/ecb.js +7 -0
  122. package/node_modules/browserify-aes/modes/index.js +18 -0
  123. package/node_modules/browserify-aes/modes/list.json +191 -0
  124. package/node_modules/browserify-aes/modes/ofb.js +16 -0
  125. package/node_modules/browserify-aes/package.json +47 -0
  126. package/node_modules/browserify-aes/streamCipher.js +27 -0
  127. package/node_modules/bs58/README.md +71 -0
  128. package/node_modules/bs58/index.js +4 -0
  129. package/node_modules/bs58/package.json +41 -0
  130. package/node_modules/bs58check/LICENSE +21 -0
  131. package/node_modules/bs58check/README.md +27 -0
  132. package/node_modules/bs58check/base.js +50 -0
  133. package/node_modules/bs58check/index.js +12 -0
  134. package/node_modules/bs58check/package.json +56 -0
  135. package/node_modules/buffer-from/LICENSE +21 -0
  136. package/node_modules/buffer-from/index.js +69 -0
  137. package/node_modules/buffer-from/package.json +23 -0
  138. package/node_modules/buffer-from/readme.md +69 -0
  139. package/node_modules/buffer-xor/.npmignore +1 -0
  140. package/node_modules/buffer-xor/.travis.yml +9 -0
  141. package/node_modules/buffer-xor/LICENSE +21 -0
  142. package/node_modules/buffer-xor/README.md +41 -0
  143. package/node_modules/buffer-xor/index.js +10 -0
  144. package/node_modules/buffer-xor/inline.js +1 -0
  145. package/node_modules/buffer-xor/inplace.js +9 -0
  146. package/node_modules/buffer-xor/package.json +41 -0
  147. package/node_modules/buffer-xor/test/fixtures.json +23 -0
  148. package/node_modules/buffer-xor/test/index.js +38 -0
  149. package/node_modules/camelcase/index.d.ts +63 -0
  150. package/node_modules/camelcase/index.js +76 -0
  151. package/node_modules/camelcase/license +9 -0
  152. package/node_modules/camelcase/package.json +47 -0
  153. package/node_modules/camelcase/readme.md +99 -0
  154. package/node_modules/cipher-base/.eslintrc +3 -0
  155. package/node_modules/cipher-base/.npmignore +1 -0
  156. package/node_modules/cipher-base/.travis.yml +6 -0
  157. package/node_modules/cipher-base/LICENSE +21 -0
  158. package/node_modules/cipher-base/README.md +17 -0
  159. package/node_modules/cipher-base/index.js +99 -0
  160. package/node_modules/cipher-base/package.json +36 -0
  161. package/node_modules/cipher-base/test.js +111 -0
  162. package/node_modules/cliui/LICENSE.txt +14 -0
  163. package/node_modules/cliui/README.md +115 -0
  164. package/node_modules/cliui/index.js +324 -0
  165. package/node_modules/cliui/package.json +71 -0
  166. package/node_modules/color-convert/LICENSE +21 -0
  167. package/node_modules/color-convert/README.md +68 -0
  168. package/node_modules/color-convert/conversions.js +868 -0
  169. package/node_modules/color-convert/index.js +78 -0
  170. package/node_modules/color-convert/package.json +50 -0
  171. package/node_modules/color-convert/route.js +97 -0
  172. package/node_modules/color-name/.eslintrc.json +43 -0
  173. package/node_modules/color-name/.npmignore +107 -0
  174. package/node_modules/color-name/LICENSE +8 -0
  175. package/node_modules/color-name/README.md +11 -0
  176. package/node_modules/color-name/index.js +152 -0
  177. package/node_modules/color-name/package.json +29 -0
  178. package/node_modules/color-name/test.js +7 -0
  179. package/node_modules/create-hash/.travis.yml +17 -0
  180. package/node_modules/create-hash/LICENSE +21 -0
  181. package/node_modules/create-hash/README.md +19 -0
  182. package/node_modules/create-hash/browser.js +30 -0
  183. package/node_modules/create-hash/index.js +1 -0
  184. package/node_modules/create-hash/md5.js +5 -0
  185. package/node_modules/create-hash/package.json +43 -0
  186. package/node_modules/create-hash/test.js +41 -0
  187. package/node_modules/create-hmac/LICENSE +21 -0
  188. package/node_modules/create-hmac/README.md +20 -0
  189. package/node_modules/create-hmac/browser.js +62 -0
  190. package/node_modules/create-hmac/index.js +1 -0
  191. package/node_modules/create-hmac/legacy.js +46 -0
  192. package/node_modules/create-hmac/package.json +49 -0
  193. package/node_modules/cross-spawn/LICENSE +21 -0
  194. package/node_modules/cross-spawn/README.md +94 -0
  195. package/node_modules/cross-spawn/index.js +39 -0
  196. package/node_modules/cross-spawn/lib/enoent.js +59 -0
  197. package/node_modules/cross-spawn/lib/parse.js +125 -0
  198. package/node_modules/cross-spawn/lib/util/escape.js +45 -0
  199. package/node_modules/cross-spawn/lib/util/readShebang.js +32 -0
  200. package/node_modules/cross-spawn/lib/util/resolveCommand.js +47 -0
  201. package/node_modules/cross-spawn/package.json +80 -0
  202. package/node_modules/decamelize/index.js +13 -0
  203. package/node_modules/decamelize/license +21 -0
  204. package/node_modules/decamelize/package.json +42 -0
  205. package/node_modules/decamelize/readme.md +48 -0
  206. package/node_modules/elliptic/README.md +238 -0
  207. package/node_modules/elliptic/lib/elliptic/curve/base.js +376 -0
  208. package/node_modules/elliptic/lib/elliptic/curve/edwards.js +432 -0
  209. package/node_modules/elliptic/lib/elliptic/curve/index.js +8 -0
  210. package/node_modules/elliptic/lib/elliptic/curve/mont.js +178 -0
  211. package/node_modules/elliptic/lib/elliptic/curve/short.js +937 -0
  212. package/node_modules/elliptic/lib/elliptic/curves.js +206 -0
  213. package/node_modules/elliptic/lib/elliptic/ec/index.js +241 -0
  214. package/node_modules/elliptic/lib/elliptic/ec/key.js +118 -0
  215. package/node_modules/elliptic/lib/elliptic/ec/signature.js +166 -0
  216. package/node_modules/elliptic/lib/elliptic/eddsa/index.js +118 -0
  217. package/node_modules/elliptic/lib/elliptic/eddsa/key.js +95 -0
  218. package/node_modules/elliptic/lib/elliptic/eddsa/signature.js +65 -0
  219. package/node_modules/elliptic/lib/elliptic/precomputed/secp256k1.js +780 -0
  220. package/node_modules/elliptic/lib/elliptic/utils.js +119 -0
  221. package/node_modules/elliptic/lib/elliptic.js +13 -0
  222. package/node_modules/elliptic/package.json +62 -0
  223. package/node_modules/emoji-regex/LICENSE-MIT.txt +20 -0
  224. package/node_modules/emoji-regex/README.md +73 -0
  225. package/node_modules/emoji-regex/es2015/index.js +6 -0
  226. package/node_modules/emoji-regex/es2015/text.js +6 -0
  227. package/node_modules/emoji-regex/index.d.ts +5 -0
  228. package/node_modules/emoji-regex/index.js +6 -0
  229. package/node_modules/emoji-regex/package.json +55 -0
  230. package/node_modules/emoji-regex/text.js +6 -0
  231. package/node_modules/end-of-stream/LICENSE +21 -0
  232. package/node_modules/end-of-stream/README.md +54 -0
  233. package/node_modules/end-of-stream/index.js +94 -0
  234. package/node_modules/end-of-stream/package.json +41 -0
  235. package/node_modules/ethereum-cryptography/LICENSE +26 -0
  236. package/node_modules/ethereum-cryptography/README.md +560 -0
  237. package/node_modules/ethereum-cryptography/aes.d.ts +4 -0
  238. package/node_modules/ethereum-cryptography/aes.d.ts.map +1 -0
  239. package/node_modules/ethereum-cryptography/aes.js +38 -0
  240. package/node_modules/ethereum-cryptography/aes.js.map +1 -0
  241. package/node_modules/ethereum-cryptography/bip39/index.d.ts +8 -0
  242. package/node_modules/ethereum-cryptography/bip39/index.d.ts.map +1 -0
  243. package/node_modules/ethereum-cryptography/bip39/index.js +71 -0
  244. package/node_modules/ethereum-cryptography/bip39/index.js.map +1 -0
  245. package/node_modules/ethereum-cryptography/bip39/wordlists/czech.d.ts +2 -0
  246. package/node_modules/ethereum-cryptography/bip39/wordlists/czech.d.ts.map +1 -0
  247. package/node_modules/ethereum-cryptography/bip39/wordlists/czech.js +2053 -0
  248. package/node_modules/ethereum-cryptography/bip39/wordlists/czech.js.map +1 -0
  249. package/node_modules/ethereum-cryptography/bip39/wordlists/english.d.ts +2 -0
  250. package/node_modules/ethereum-cryptography/bip39/wordlists/english.d.ts.map +1 -0
  251. package/node_modules/ethereum-cryptography/bip39/wordlists/english.js +2053 -0
  252. package/node_modules/ethereum-cryptography/bip39/wordlists/english.js.map +1 -0
  253. package/node_modules/ethereum-cryptography/bip39/wordlists/french.d.ts +2 -0
  254. package/node_modules/ethereum-cryptography/bip39/wordlists/french.d.ts.map +1 -0
  255. package/node_modules/ethereum-cryptography/bip39/wordlists/french.js +2053 -0
  256. package/node_modules/ethereum-cryptography/bip39/wordlists/french.js.map +1 -0
  257. package/node_modules/ethereum-cryptography/bip39/wordlists/italian.d.ts +2 -0
  258. package/node_modules/ethereum-cryptography/bip39/wordlists/italian.d.ts.map +1 -0
  259. package/node_modules/ethereum-cryptography/bip39/wordlists/italian.js +2053 -0
  260. package/node_modules/ethereum-cryptography/bip39/wordlists/italian.js.map +1 -0
  261. package/node_modules/ethereum-cryptography/bip39/wordlists/japanese.d.ts +2 -0
  262. package/node_modules/ethereum-cryptography/bip39/wordlists/japanese.d.ts.map +1 -0
  263. package/node_modules/ethereum-cryptography/bip39/wordlists/japanese.js +2053 -0
  264. package/node_modules/ethereum-cryptography/bip39/wordlists/japanese.js.map +1 -0
  265. package/node_modules/ethereum-cryptography/bip39/wordlists/korean.d.ts +2 -0
  266. package/node_modules/ethereum-cryptography/bip39/wordlists/korean.d.ts.map +1 -0
  267. package/node_modules/ethereum-cryptography/bip39/wordlists/korean.js +2053 -0
  268. package/node_modules/ethereum-cryptography/bip39/wordlists/korean.js.map +1 -0
  269. package/node_modules/ethereum-cryptography/bip39/wordlists/simplified-chinese.d.ts +2 -0
  270. package/node_modules/ethereum-cryptography/bip39/wordlists/simplified-chinese.d.ts.map +1 -0
  271. package/node_modules/ethereum-cryptography/bip39/wordlists/simplified-chinese.js +2053 -0
  272. package/node_modules/ethereum-cryptography/bip39/wordlists/simplified-chinese.js.map +1 -0
  273. package/node_modules/ethereum-cryptography/bip39/wordlists/spanish.d.ts +2 -0
  274. package/node_modules/ethereum-cryptography/bip39/wordlists/spanish.d.ts.map +1 -0
  275. package/node_modules/ethereum-cryptography/bip39/wordlists/spanish.js +2053 -0
  276. package/node_modules/ethereum-cryptography/bip39/wordlists/spanish.js.map +1 -0
  277. package/node_modules/ethereum-cryptography/bip39/wordlists/traditional-chinese.d.ts +2 -0
  278. package/node_modules/ethereum-cryptography/bip39/wordlists/traditional-chinese.d.ts.map +1 -0
  279. package/node_modules/ethereum-cryptography/bip39/wordlists/traditional-chinese.js +2053 -0
  280. package/node_modules/ethereum-cryptography/bip39/wordlists/traditional-chinese.js.map +1 -0
  281. package/node_modules/ethereum-cryptography/blake2b.d.ts +3 -0
  282. package/node_modules/ethereum-cryptography/blake2b.d.ts.map +1 -0
  283. package/node_modules/ethereum-cryptography/blake2b.js +12 -0
  284. package/node_modules/ethereum-cryptography/blake2b.js.map +1 -0
  285. package/node_modules/ethereum-cryptography/hash-utils.d.ts +4 -0
  286. package/node_modules/ethereum-cryptography/hash-utils.d.ts.map +1 -0
  287. package/node_modules/ethereum-cryptography/hash-utils.js +11 -0
  288. package/node_modules/ethereum-cryptography/hash-utils.js.map +1 -0
  289. package/node_modules/ethereum-cryptography/hdkey.d.ts +3 -0
  290. package/node_modules/ethereum-cryptography/hdkey.d.ts.map +1 -0
  291. package/node_modules/ethereum-cryptography/hdkey.js +5 -0
  292. package/node_modules/ethereum-cryptography/hdkey.js.map +1 -0
  293. package/node_modules/ethereum-cryptography/index.d.ts +1 -0
  294. package/node_modules/ethereum-cryptography/index.d.ts.map +1 -0
  295. package/node_modules/ethereum-cryptography/index.js +3 -0
  296. package/node_modules/ethereum-cryptography/index.js.map +1 -0
  297. package/node_modules/ethereum-cryptography/keccak.d.ts +6 -0
  298. package/node_modules/ethereum-cryptography/keccak.d.ts.map +1 -0
  299. package/node_modules/ethereum-cryptography/keccak.js +17 -0
  300. package/node_modules/ethereum-cryptography/keccak.js.map +1 -0
  301. package/node_modules/ethereum-cryptography/package.json +131 -0
  302. package/node_modules/ethereum-cryptography/pbkdf2.d.ts +4 -0
  303. package/node_modules/ethereum-cryptography/pbkdf2.d.ts.map +1 -0
  304. package/node_modules/ethereum-cryptography/pbkdf2.js +27 -0
  305. package/node_modules/ethereum-cryptography/pbkdf2.js.map +1 -0
  306. package/node_modules/ethereum-cryptography/pure/hdkey.d.ts +37 -0
  307. package/node_modules/ethereum-cryptography/pure/hdkey.d.ts.map +1 -0
  308. package/node_modules/ethereum-cryptography/pure/hdkey.js +5 -0
  309. package/node_modules/ethereum-cryptography/pure/hdkey.js.map +1 -0
  310. package/node_modules/ethereum-cryptography/pure/ripemd160.d.ts +3 -0
  311. package/node_modules/ethereum-cryptography/pure/ripemd160.d.ts.map +1 -0
  312. package/node_modules/ethereum-cryptography/pure/ripemd160.js +6 -0
  313. package/node_modules/ethereum-cryptography/pure/ripemd160.js.map +1 -0
  314. package/node_modules/ethereum-cryptography/pure/sha256.d.ts +3 -0
  315. package/node_modules/ethereum-cryptography/pure/sha256.d.ts.map +1 -0
  316. package/node_modules/ethereum-cryptography/pure/sha256.js +6 -0
  317. package/node_modules/ethereum-cryptography/pure/sha256.js.map +1 -0
  318. package/node_modules/ethereum-cryptography/pure/shims/hdkey-crypto.d.ts +13 -0
  319. package/node_modules/ethereum-cryptography/pure/shims/hdkey-crypto.d.ts.map +1 -0
  320. package/node_modules/ethereum-cryptography/pure/shims/hdkey-crypto.js +37 -0
  321. package/node_modules/ethereum-cryptography/pure/shims/hdkey-crypto.js.map +1 -0
  322. package/node_modules/ethereum-cryptography/pure/shims/hdkey-secp256k1v3.d.ts +2 -0
  323. package/node_modules/ethereum-cryptography/pure/shims/hdkey-secp256k1v3.d.ts.map +1 -0
  324. package/node_modules/ethereum-cryptography/pure/shims/hdkey-secp256k1v3.js +7 -0
  325. package/node_modules/ethereum-cryptography/pure/shims/hdkey-secp256k1v3.js.map +1 -0
  326. package/node_modules/ethereum-cryptography/pure/vendor/hdkey-without-crypto.js +255 -0
  327. package/node_modules/ethereum-cryptography/random.d.ts +4 -0
  328. package/node_modules/ethereum-cryptography/random.d.ts.map +1 -0
  329. package/node_modules/ethereum-cryptography/random.js +20 -0
  330. package/node_modules/ethereum-cryptography/random.js.map +1 -0
  331. package/node_modules/ethereum-cryptography/ripemd160.d.ts +3 -0
  332. package/node_modules/ethereum-cryptography/ripemd160.d.ts.map +1 -0
  333. package/node_modules/ethereum-cryptography/ripemd160.js +11 -0
  334. package/node_modules/ethereum-cryptography/ripemd160.js.map +1 -0
  335. package/node_modules/ethereum-cryptography/scrypt.d.ts +5 -0
  336. package/node_modules/ethereum-cryptography/scrypt.d.ts.map +1 -0
  337. package/node_modules/ethereum-cryptography/scrypt.js +59 -0
  338. package/node_modules/ethereum-cryptography/scrypt.js.map +1 -0
  339. package/node_modules/ethereum-cryptography/secp256k1.d.ts +4 -0
  340. package/node_modules/ethereum-cryptography/secp256k1.d.ts.map +1 -0
  341. package/node_modules/ethereum-cryptography/secp256k1.js +75 -0
  342. package/node_modules/ethereum-cryptography/secp256k1.js.map +1 -0
  343. package/node_modules/ethereum-cryptography/sha256.d.ts +3 -0
  344. package/node_modules/ethereum-cryptography/sha256.d.ts.map +1 -0
  345. package/node_modules/ethereum-cryptography/sha256.js +9 -0
  346. package/node_modules/ethereum-cryptography/sha256.js.map +1 -0
  347. package/node_modules/ethereum-cryptography/shims/hdkey-crypto.d.ts +2 -0
  348. package/node_modules/ethereum-cryptography/shims/hdkey-crypto.d.ts.map +1 -0
  349. package/node_modules/ethereum-cryptography/shims/hdkey-crypto.js +7 -0
  350. package/node_modules/ethereum-cryptography/shims/hdkey-crypto.js.map +1 -0
  351. package/node_modules/ethereum-cryptography/shims/hdkey-secp256k1v3.d.ts +13 -0
  352. package/node_modules/ethereum-cryptography/shims/hdkey-secp256k1v3.d.ts.map +1 -0
  353. package/node_modules/ethereum-cryptography/shims/hdkey-secp256k1v3.js +47 -0
  354. package/node_modules/ethereum-cryptography/shims/hdkey-secp256k1v3.js.map +1 -0
  355. package/node_modules/ethereum-cryptography/src/aes.ts +52 -0
  356. package/node_modules/ethereum-cryptography/src/bip39/index.ts +40 -0
  357. package/node_modules/ethereum-cryptography/src/bip39/wordlists/czech.ts +2050 -0
  358. package/node_modules/ethereum-cryptography/src/bip39/wordlists/english.ts +2050 -0
  359. package/node_modules/ethereum-cryptography/src/bip39/wordlists/french.ts +2050 -0
  360. package/node_modules/ethereum-cryptography/src/bip39/wordlists/italian.ts +2050 -0
  361. package/node_modules/ethereum-cryptography/src/bip39/wordlists/japanese.ts +2050 -0
  362. package/node_modules/ethereum-cryptography/src/bip39/wordlists/korean.ts +2050 -0
  363. package/node_modules/ethereum-cryptography/src/bip39/wordlists/simplified-chinese.ts +2050 -0
  364. package/node_modules/ethereum-cryptography/src/bip39/wordlists/spanish.ts +2050 -0
  365. package/node_modules/ethereum-cryptography/src/bip39/wordlists/traditional-chinese.ts +2050 -0
  366. package/node_modules/ethereum-cryptography/src/blake2b.ts +9 -0
  367. package/node_modules/ethereum-cryptography/src/hash-utils.ts +11 -0
  368. package/node_modules/ethereum-cryptography/src/hdkey.ts +5 -0
  369. package/node_modules/ethereum-cryptography/src/index.ts +3 -0
  370. package/node_modules/ethereum-cryptography/src/keccak.ts +19 -0
  371. package/node_modules/ethereum-cryptography/src/pbkdf2.ts +37 -0
  372. package/node_modules/ethereum-cryptography/src/pure/hdkey.ts +36 -0
  373. package/node_modules/ethereum-cryptography/src/pure/ripemd160.ts +5 -0
  374. package/node_modules/ethereum-cryptography/src/pure/sha256.ts +5 -0
  375. package/node_modules/ethereum-cryptography/src/pure/shims/hdkey-crypto.ts +42 -0
  376. package/node_modules/ethereum-cryptography/src/pure/shims/hdkey-secp256k1v3.ts +1 -0
  377. package/node_modules/ethereum-cryptography/src/pure/vendor/hdkey-without-crypto.js +255 -0
  378. package/node_modules/ethereum-cryptography/src/random.ts +18 -0
  379. package/node_modules/ethereum-cryptography/src/ripemd160.ts +7 -0
  380. package/node_modules/ethereum-cryptography/src/scrypt.ts +24 -0
  381. package/node_modules/ethereum-cryptography/src/secp256k1.ts +24 -0
  382. package/node_modules/ethereum-cryptography/src/sha256.ts +5 -0
  383. package/node_modules/ethereum-cryptography/src/shims/hdkey-crypto.ts +1 -0
  384. package/node_modules/ethereum-cryptography/src/shims/hdkey-secp256k1v3.ts +49 -0
  385. package/node_modules/ethereum-cryptography/src/vendor/bip39-without-wordlists.js +206 -0
  386. package/node_modules/ethereum-cryptography/src/vendor/hdkey-without-crypto.js +255 -0
  387. package/node_modules/ethereum-cryptography/vendor/bip39-without-wordlists.js +206 -0
  388. package/node_modules/ethereum-cryptography/vendor/hdkey-without-crypto.js +255 -0
  389. package/node_modules/ethereumjs-util/LICENSE +373 -0
  390. package/node_modules/ethereumjs-util/README.md +32 -0
  391. package/node_modules/ethereumjs-util/dist/account.d.ts +80 -0
  392. package/node_modules/ethereumjs-util/dist/account.js +168 -0
  393. package/node_modules/ethereumjs-util/dist/account.js.map +1 -0
  394. package/node_modules/ethereumjs-util/dist/bytes.d.ts +68 -0
  395. package/node_modules/ethereumjs-util/dist/bytes.js +158 -0
  396. package/node_modules/ethereumjs-util/dist/bytes.js.map +1 -0
  397. package/node_modules/ethereumjs-util/dist/constants.d.ts +34 -0
  398. package/node_modules/ethereumjs-util/dist/constants.js +37 -0
  399. package/node_modules/ethereumjs-util/dist/constants.js.map +1 -0
  400. package/node_modules/ethereumjs-util/dist/hash.d.ts +30 -0
  401. package/node_modules/ethereumjs-util/dist/hash.js +84 -0
  402. package/node_modules/ethereumjs-util/dist/hash.js.map +1 -0
  403. package/node_modules/ethereumjs-util/dist/index.d.ts +39 -0
  404. package/node_modules/ethereumjs-util/dist/index.js +46 -0
  405. package/node_modules/ethereumjs-util/dist/index.js.map +1 -0
  406. package/node_modules/ethereumjs-util/dist/object.d.ts +12 -0
  407. package/node_modules/ethereumjs-util/dist/object.js +106 -0
  408. package/node_modules/ethereumjs-util/dist/object.js.map +1 -0
  409. package/node_modules/ethereumjs-util/dist/secp256k1v3-adapter.d.ts +178 -0
  410. package/node_modules/ethereumjs-util/dist/secp256k1v3-adapter.js +300 -0
  411. package/node_modules/ethereumjs-util/dist/secp256k1v3-adapter.js.map +1 -0
  412. package/node_modules/ethereumjs-util/dist/secp256k1v3-lib/der.d.ts +1 -0
  413. package/node_modules/ethereumjs-util/dist/secp256k1v3-lib/der.js +634 -0
  414. package/node_modules/ethereumjs-util/dist/secp256k1v3-lib/der.js.map +1 -0
  415. package/node_modules/ethereumjs-util/dist/secp256k1v3-lib/index.d.ts +5 -0
  416. package/node_modules/ethereumjs-util/dist/secp256k1v3-lib/index.js +61 -0
  417. package/node_modules/ethereumjs-util/dist/secp256k1v3-lib/index.js.map +1 -0
  418. package/node_modules/ethereumjs-util/dist/signature.d.ts +37 -0
  419. package/node_modules/ethereumjs-util/dist/signature.js +107 -0
  420. package/node_modules/ethereumjs-util/dist/signature.js.map +1 -0
  421. package/node_modules/ethereumjs-util/package.json +131 -0
  422. package/node_modules/ethjs-util/LICENSE +21 -0
  423. package/node_modules/ethjs-util/README.md +143 -0
  424. package/node_modules/ethjs-util/dist/ethjs-util.js +2420 -0
  425. package/node_modules/ethjs-util/dist/ethjs-util.js.map +1 -0
  426. package/node_modules/ethjs-util/dist/ethjs-util.min.js +1 -0
  427. package/node_modules/ethjs-util/internals/webpack/webpack.config.js +58 -0
  428. package/node_modules/ethjs-util/lib/index.js +220 -0
  429. package/node_modules/ethjs-util/lib/tests/test.index.js +357 -0
  430. package/node_modules/ethjs-util/package.json +229 -0
  431. package/node_modules/ethjs-util/src/index.js +203 -0
  432. package/node_modules/ethjs-util/src/tests/test.index.js +382 -0
  433. package/node_modules/evp_bytestokey/LICENSE +21 -0
  434. package/node_modules/evp_bytestokey/README.md +51 -0
  435. package/node_modules/evp_bytestokey/index.js +45 -0
  436. package/node_modules/evp_bytestokey/package.json +49 -0
  437. package/node_modules/execa/index.js +361 -0
  438. package/node_modules/execa/lib/errname.js +39 -0
  439. package/node_modules/execa/lib/stdio.js +41 -0
  440. package/node_modules/execa/license +9 -0
  441. package/node_modules/execa/package.json +73 -0
  442. package/node_modules/execa/readme.md +327 -0
  443. package/node_modules/find-up/index.js +46 -0
  444. package/node_modules/find-up/license +9 -0
  445. package/node_modules/find-up/package.json +54 -0
  446. package/node_modules/find-up/readme.md +87 -0
  447. package/node_modules/get-caller-file/LICENSE.md +6 -0
  448. package/node_modules/get-caller-file/README.md +41 -0
  449. package/node_modules/get-caller-file/index.d.ts +2 -0
  450. package/node_modules/get-caller-file/index.js +22 -0
  451. package/node_modules/get-caller-file/index.js.map +1 -0
  452. package/node_modules/get-caller-file/package.json +46 -0
  453. package/node_modules/get-stream/buffer-stream.js +51 -0
  454. package/node_modules/get-stream/index.js +50 -0
  455. package/node_modules/get-stream/license +9 -0
  456. package/node_modules/get-stream/package.json +50 -0
  457. package/node_modules/get-stream/readme.md +123 -0
  458. package/node_modules/hash-base/LICENSE +21 -0
  459. package/node_modules/hash-base/README.md +48 -0
  460. package/node_modules/hash-base/index.js +95 -0
  461. package/node_modules/hash-base/package.json +46 -0
  462. package/node_modules/hash.js/.eslintrc.js +41 -0
  463. package/node_modules/hash.js/.travis.yml +10 -0
  464. package/node_modules/hash.js/README.md +48 -0
  465. package/node_modules/hash.js/lib/hash/common.js +92 -0
  466. package/node_modules/hash.js/lib/hash/hmac.js +47 -0
  467. package/node_modules/hash.js/lib/hash/ripemd.js +146 -0
  468. package/node_modules/hash.js/lib/hash/sha/1.js +74 -0
  469. package/node_modules/hash.js/lib/hash/sha/224.js +30 -0
  470. package/node_modules/hash.js/lib/hash/sha/256.js +105 -0
  471. package/node_modules/hash.js/lib/hash/sha/384.js +35 -0
  472. package/node_modules/hash.js/lib/hash/sha/512.js +330 -0
  473. package/node_modules/hash.js/lib/hash/sha/common.js +49 -0
  474. package/node_modules/hash.js/lib/hash/sha.js +7 -0
  475. package/node_modules/hash.js/lib/hash/utils.js +278 -0
  476. package/node_modules/hash.js/lib/hash.d.ts +106 -0
  477. package/node_modules/hash.js/lib/hash.js +15 -0
  478. package/node_modules/hash.js/package.json +39 -0
  479. package/node_modules/hash.js/test/hash-test.js +140 -0
  480. package/node_modules/hash.js/test/hmac-test.js +62 -0
  481. package/node_modules/hmac-drbg/.npmignore +2 -0
  482. package/node_modules/hmac-drbg/.travis.yml +11 -0
  483. package/node_modules/hmac-drbg/README.md +48 -0
  484. package/node_modules/hmac-drbg/lib/hmac-drbg.js +113 -0
  485. package/node_modules/hmac-drbg/package.json +36 -0
  486. package/node_modules/hmac-drbg/test/drbg-test.js +91 -0
  487. package/node_modules/hmac-drbg/test/fixtures/hmac-drbg-nist.json +332 -0
  488. package/node_modules/inherits/LICENSE +16 -0
  489. package/node_modules/inherits/README.md +42 -0
  490. package/node_modules/inherits/inherits.js +9 -0
  491. package/node_modules/inherits/inherits_browser.js +27 -0
  492. package/node_modules/inherits/package.json +33 -0
  493. package/node_modules/invert-kv/index.js +15 -0
  494. package/node_modules/invert-kv/license +9 -0
  495. package/node_modules/invert-kv/package.json +36 -0
  496. package/node_modules/invert-kv/readme.md +25 -0
  497. package/node_modules/is-fullwidth-code-point/index.js +46 -0
  498. package/node_modules/is-fullwidth-code-point/license +21 -0
  499. package/node_modules/is-fullwidth-code-point/package.json +49 -0
  500. package/node_modules/is-fullwidth-code-point/readme.md +39 -0
  501. package/node_modules/is-hex-prefixed/.editorconfig +7 -0
  502. package/node_modules/is-hex-prefixed/.gitattributes +106 -0
  503. package/node_modules/is-hex-prefixed/.npmignore +8 -0
  504. package/node_modules/is-hex-prefixed/.travis.yml +5 -0
  505. package/node_modules/is-hex-prefixed/CHANGELOG.md +7 -0
  506. package/node_modules/is-hex-prefixed/LICENSE +21 -0
  507. package/node_modules/is-hex-prefixed/README.md +101 -0
  508. package/node_modules/is-hex-prefixed/package.json +43 -0
  509. package/node_modules/is-hex-prefixed/src/index.js +13 -0
  510. package/node_modules/is-hex-prefixed/src/tests/test.index.js +66 -0
  511. package/node_modules/is-stream/index.js +21 -0
  512. package/node_modules/is-stream/license +21 -0
  513. package/node_modules/is-stream/package.json +42 -0
  514. package/node_modules/is-stream/readme.md +42 -0
  515. package/node_modules/isexe/.npmignore +2 -0
  516. package/node_modules/isexe/LICENSE +15 -0
  517. package/node_modules/isexe/README.md +51 -0
  518. package/node_modules/isexe/index.js +57 -0
  519. package/node_modules/isexe/mode.js +41 -0
  520. package/node_modules/isexe/package.json +35 -0
  521. package/node_modules/isexe/test/basic.js +221 -0
  522. package/node_modules/isexe/windows.js +42 -0
  523. package/node_modules/keccak/LICENSE +21 -0
  524. package/node_modules/keccak/README.md +64 -0
  525. package/node_modules/keccak/binding.gyp +78 -0
  526. package/node_modules/keccak/bindings.js +1 -0
  527. package/node_modules/keccak/index.js +5 -0
  528. package/node_modules/keccak/js.js +1 -0
  529. package/node_modules/keccak/lib/api/index.js +27 -0
  530. package/node_modules/keccak/lib/api/keccak.js +77 -0
  531. package/node_modules/keccak/lib/api/shake.js +68 -0
  532. package/node_modules/keccak/lib/keccak-state-reference.js +143 -0
  533. package/node_modules/keccak/lib/keccak-state-unroll.js +186 -0
  534. package/node_modules/keccak/lib/keccak.js +68 -0
  535. package/node_modules/keccak/package.json +41 -0
  536. package/node_modules/keccak/prebuilds/darwin-x64/node.napi.node +0 -0
  537. package/node_modules/keccak/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  538. package/node_modules/keccak/prebuilds/linux-x64/node.napi.musl.node +0 -0
  539. package/node_modules/keccak/prebuilds/win32-x64/node.napi.node +0 -0
  540. package/node_modules/keccak/src/README.md +28 -0
  541. package/node_modules/keccak/src/addon.cc +98 -0
  542. package/node_modules/keccak/src/libkeccak-32/KeccakP-1600-SnP.h +38 -0
  543. package/node_modules/keccak/src/libkeccak-32/KeccakP-1600-inplace32BI.c +1162 -0
  544. package/node_modules/keccak/src/libkeccak-32/KeccakSponge-common.h +35 -0
  545. package/node_modules/keccak/src/libkeccak-32/KeccakSponge.inc +311 -0
  546. package/node_modules/keccak/src/libkeccak-32/KeccakSpongeWidth1600.c +54 -0
  547. package/node_modules/keccak/src/libkeccak-32/KeccakSpongeWidth1600.h +31 -0
  548. package/node_modules/keccak/src/libkeccak-32/SnP-Relaned.h +140 -0
  549. package/node_modules/keccak/src/libkeccak-32/align.h +32 -0
  550. package/node_modules/keccak/src/libkeccak-32/brg_endian.h +143 -0
  551. package/node_modules/keccak/src/libkeccak-64/KeccakP-1600-64.macros +745 -0
  552. package/node_modules/keccak/src/libkeccak-64/KeccakP-1600-SnP.h +51 -0
  553. package/node_modules/keccak/src/libkeccak-64/KeccakP-1600-opt64-config.h +6 -0
  554. package/node_modules/keccak/src/libkeccak-64/KeccakP-1600-opt64.c +564 -0
  555. package/node_modules/keccak/src/libkeccak-64/KeccakP-1600-unrolling.macros +302 -0
  556. package/node_modules/keccak/src/libkeccak-64/KeccakSponge-common.h +35 -0
  557. package/node_modules/keccak/src/libkeccak-64/KeccakSponge.inc +311 -0
  558. package/node_modules/keccak/src/libkeccak-64/KeccakSpongeWidth1600.c +54 -0
  559. package/node_modules/keccak/src/libkeccak-64/KeccakSpongeWidth1600.h +31 -0
  560. package/node_modules/keccak/src/libkeccak-64/SnP-Relaned.h +140 -0
  561. package/node_modules/keccak/src/libkeccak-64/align.h +32 -0
  562. package/node_modules/keccak/src/libkeccak-64/brg_endian.h +143 -0
  563. package/node_modules/lcid/index.js +23 -0
  564. package/node_modules/lcid/lcid.json +203 -0
  565. package/node_modules/lcid/license +9 -0
  566. package/node_modules/lcid/package.json +51 -0
  567. package/node_modules/lcid/readme.md +35 -0
  568. package/node_modules/locate-path/index.js +24 -0
  569. package/node_modules/locate-path/license +9 -0
  570. package/node_modules/locate-path/package.json +48 -0
  571. package/node_modules/locate-path/readme.md +99 -0
  572. package/node_modules/map-age-cleaner/dist/index.d.ts +20 -0
  573. package/node_modules/map-age-cleaner/dist/index.js +92 -0
  574. package/node_modules/map-age-cleaner/license +9 -0
  575. package/node_modules/map-age-cleaner/package.json +63 -0
  576. package/node_modules/map-age-cleaner/readme.md +67 -0
  577. package/node_modules/md5.js/LICENSE +21 -0
  578. package/node_modules/md5.js/README.md +29 -0
  579. package/node_modules/md5.js/index.js +146 -0
  580. package/node_modules/md5.js/package.json +42 -0
  581. package/node_modules/mem/index.d.ts +96 -0
  582. package/node_modules/mem/index.js +88 -0
  583. package/node_modules/mem/license +9 -0
  584. package/node_modules/mem/package.json +50 -0
  585. package/node_modules/mem/readme.md +167 -0
  586. package/node_modules/mimic-fn/index.d.ts +54 -0
  587. package/node_modules/mimic-fn/index.js +13 -0
  588. package/node_modules/mimic-fn/license +9 -0
  589. package/node_modules/mimic-fn/package.json +46 -0
  590. package/node_modules/mimic-fn/readme.md +69 -0
  591. package/node_modules/minimalistic-assert/LICENSE +13 -0
  592. package/node_modules/minimalistic-assert/index.js +11 -0
  593. package/node_modules/minimalistic-assert/package.json +23 -0
  594. package/node_modules/minimalistic-assert/readme.md +4 -0
  595. package/node_modules/minimalistic-crypto-utils/.npmignore +2 -0
  596. package/node_modules/minimalistic-crypto-utils/.travis.yml +11 -0
  597. package/node_modules/minimalistic-crypto-utils/README.md +47 -0
  598. package/node_modules/minimalistic-crypto-utils/lib/utils.js +58 -0
  599. package/node_modules/minimalistic-crypto-utils/package.json +31 -0
  600. package/node_modules/minimalistic-crypto-utils/test/utils-test.js +28 -0
  601. package/node_modules/nice-try/LICENSE +21 -0
  602. package/node_modules/nice-try/README.md +32 -0
  603. package/node_modules/nice-try/package.json +37 -0
  604. package/node_modules/nice-try/src/index.js +12 -0
  605. package/node_modules/node-addon-api/.editorconfig +8 -0
  606. package/node_modules/node-addon-api/.travis.yml +62 -0
  607. package/node_modules/node-addon-api/CHANGELOG.md +412 -0
  608. package/node_modules/node-addon-api/CODE_OF_CONDUCT.md +4 -0
  609. package/node_modules/node-addon-api/CONTRIBUTING.md +66 -0
  610. package/node_modules/node-addon-api/LICENSE.md +13 -0
  611. package/node_modules/node-addon-api/README.md +203 -0
  612. package/node_modules/node-addon-api/appveyor.yml +48 -0
  613. package/node_modules/node-addon-api/doc/Doxyfile +2450 -0
  614. package/node_modules/node-addon-api/doc/array_buffer.md +129 -0
  615. package/node_modules/node-addon-api/doc/async_context.md +86 -0
  616. package/node_modules/node-addon-api/doc/async_operations.md +31 -0
  617. package/node_modules/node-addon-api/doc/async_progress_worker.md +344 -0
  618. package/node_modules/node-addon-api/doc/async_worker.md +398 -0
  619. package/node_modules/node-addon-api/doc/basic_types.md +423 -0
  620. package/node_modules/node-addon-api/doc/bigint.md +92 -0
  621. package/node_modules/node-addon-api/doc/boolean.md +64 -0
  622. package/node_modules/node-addon-api/doc/buffer.md +140 -0
  623. package/node_modules/node-addon-api/doc/callback_scope.md +54 -0
  624. package/node_modules/node-addon-api/doc/callbackinfo.md +97 -0
  625. package/node_modules/node-addon-api/doc/checker-tool.md +32 -0
  626. package/node_modules/node-addon-api/doc/class_property_descriptor.md +117 -0
  627. package/node_modules/node-addon-api/doc/cmake-js.md +68 -0
  628. package/node_modules/node-addon-api/doc/conversion-tool.md +28 -0
  629. package/node_modules/node-addon-api/doc/creating_a_release.md +62 -0
  630. package/node_modules/node-addon-api/doc/dataview.md +244 -0
  631. package/node_modules/node-addon-api/doc/date.md +68 -0
  632. package/node_modules/node-addon-api/doc/env.md +63 -0
  633. package/node_modules/node-addon-api/doc/error.md +115 -0
  634. package/node_modules/node-addon-api/doc/error_handling.md +186 -0
  635. package/node_modules/node-addon-api/doc/escapable_handle_scope.md +82 -0
  636. package/node_modules/node-addon-api/doc/external.md +59 -0
  637. package/node_modules/node-addon-api/doc/function.md +294 -0
  638. package/node_modules/node-addon-api/doc/function_reference.md +238 -0
  639. package/node_modules/node-addon-api/doc/generator.md +13 -0
  640. package/node_modules/node-addon-api/doc/handle_scope.md +65 -0
  641. package/node_modules/node-addon-api/doc/memory_management.md +27 -0
  642. package/node_modules/node-addon-api/doc/node-gyp.md +82 -0
  643. package/node_modules/node-addon-api/doc/number.md +163 -0
  644. package/node_modules/node-addon-api/doc/object.md +236 -0
  645. package/node_modules/node-addon-api/doc/object_lifetime_management.md +83 -0
  646. package/node_modules/node-addon-api/doc/object_reference.md +117 -0
  647. package/node_modules/node-addon-api/doc/object_wrap.md +557 -0
  648. package/node_modules/node-addon-api/doc/prebuild_tools.md +16 -0
  649. package/node_modules/node-addon-api/doc/promises.md +74 -0
  650. package/node_modules/node-addon-api/doc/property_descriptor.md +231 -0
  651. package/node_modules/node-addon-api/doc/range_error.md +59 -0
  652. package/node_modules/node-addon-api/doc/reference.md +111 -0
  653. package/node_modules/node-addon-api/doc/setup.md +82 -0
  654. package/node_modules/node-addon-api/doc/string.md +89 -0
  655. package/node_modules/node-addon-api/doc/symbol.md +44 -0
  656. package/node_modules/node-addon-api/doc/threadsafe_function.md +320 -0
  657. package/node_modules/node-addon-api/doc/type_error.md +59 -0
  658. package/node_modules/node-addon-api/doc/typed_array.md +74 -0
  659. package/node_modules/node-addon-api/doc/typed_array_of.md +133 -0
  660. package/node_modules/node-addon-api/doc/value.md +278 -0
  661. package/node_modules/node-addon-api/doc/version_management.md +43 -0
  662. package/node_modules/node-addon-api/doc/working_with_javascript_values.md +14 -0
  663. package/node_modules/node-addon-api/external-napi/node_api.h +7 -0
  664. package/node_modules/node-addon-api/index.js +45 -0
  665. package/node_modules/node-addon-api/napi-inl.deprecated.h +192 -0
  666. package/node_modules/node-addon-api/napi-inl.h +4412 -0
  667. package/node_modules/node-addon-api/napi.h +2173 -0
  668. package/node_modules/node-addon-api/package.json +248 -0
  669. package/node_modules/node-addon-api/src/node_api.cc +3655 -0
  670. package/node_modules/node-addon-api/src/node_api.gyp +21 -0
  671. package/node_modules/node-addon-api/src/node_api.h +588 -0
  672. package/node_modules/node-addon-api/src/node_api_types.h +115 -0
  673. package/node_modules/node-addon-api/src/node_internals.cc +142 -0
  674. package/node_modules/node-addon-api/src/node_internals.h +157 -0
  675. package/node_modules/node-addon-api/src/nothing.c +0 -0
  676. package/node_modules/node-addon-api/src/util-inl.h +38 -0
  677. package/node_modules/node-addon-api/src/util.h +7 -0
  678. package/node_modules/node-addon-api/tools/README.md +67 -0
  679. package/node_modules/node-addon-api/tools/check-napi.js +100 -0
  680. package/node_modules/node-addon-api/tools/conversion.js +313 -0
  681. package/node_modules/node-gyp-build/LICENSE +21 -0
  682. package/node_modules/node-gyp-build/README.md +58 -0
  683. package/node_modules/node-gyp-build/bin.js +77 -0
  684. package/node_modules/node-gyp-build/build-test.js +19 -0
  685. package/node_modules/node-gyp-build/index.js +166 -0
  686. package/node_modules/node-gyp-build/optional.js +7 -0
  687. package/node_modules/node-gyp-build/package.json +33 -0
  688. package/node_modules/npm-run-path/index.js +39 -0
  689. package/node_modules/npm-run-path/license +21 -0
  690. package/node_modules/npm-run-path/package.json +49 -0
  691. package/node_modules/npm-run-path/readme.md +81 -0
  692. package/node_modules/once/LICENSE +15 -0
  693. package/node_modules/once/README.md +79 -0
  694. package/node_modules/once/once.js +42 -0
  695. package/node_modules/once/package.json +37 -0
  696. package/node_modules/os-locale/index.js +114 -0
  697. package/node_modules/os-locale/license +9 -0
  698. package/node_modules/os-locale/package.json +49 -0
  699. package/node_modules/os-locale/readme.md +71 -0
  700. package/node_modules/p-defer/index.js +11 -0
  701. package/node_modules/p-defer/license +21 -0
  702. package/node_modules/p-defer/package.json +45 -0
  703. package/node_modules/p-defer/readme.md +47 -0
  704. package/node_modules/p-finally/index.js +15 -0
  705. package/node_modules/p-finally/license +21 -0
  706. package/node_modules/p-finally/package.json +46 -0
  707. package/node_modules/p-finally/readme.md +47 -0
  708. package/node_modules/p-is-promise/index.d.ts +23 -0
  709. package/node_modules/p-is-promise/index.js +15 -0
  710. package/node_modules/p-is-promise/license +9 -0
  711. package/node_modules/p-is-promise/package.json +46 -0
  712. package/node_modules/p-is-promise/readme.md +43 -0
  713. package/node_modules/p-limit/index.d.ts +38 -0
  714. package/node_modules/p-limit/index.js +57 -0
  715. package/node_modules/p-limit/license +9 -0
  716. package/node_modules/p-limit/package.json +56 -0
  717. package/node_modules/p-limit/readme.md +101 -0
  718. package/node_modules/p-locate/index.js +34 -0
  719. package/node_modules/p-locate/license +9 -0
  720. package/node_modules/p-locate/package.json +55 -0
  721. package/node_modules/p-locate/readme.md +88 -0
  722. package/node_modules/p-try/index.d.ts +39 -0
  723. package/node_modules/p-try/index.js +9 -0
  724. package/node_modules/p-try/license +9 -0
  725. package/node_modules/p-try/package.json +46 -0
  726. package/node_modules/p-try/readme.md +58 -0
  727. package/node_modules/path-exists/index.js +17 -0
  728. package/node_modules/path-exists/license +21 -0
  729. package/node_modules/path-exists/package.json +44 -0
  730. package/node_modules/path-exists/readme.md +50 -0
  731. package/node_modules/path-key/index.js +13 -0
  732. package/node_modules/path-key/license +21 -0
  733. package/node_modules/path-key/package.json +43 -0
  734. package/node_modules/path-key/readme.md +51 -0
  735. package/node_modules/pbkdf2/LICENSE +21 -0
  736. package/node_modules/pbkdf2/README.md +30 -0
  737. package/node_modules/pbkdf2/browser.js +2 -0
  738. package/node_modules/pbkdf2/index.js +38 -0
  739. package/node_modules/pbkdf2/lib/async.js +102 -0
  740. package/node_modules/pbkdf2/lib/default-encoding.js +12 -0
  741. package/node_modules/pbkdf2/lib/precondition.js +19 -0
  742. package/node_modules/pbkdf2/lib/sync-browser.js +105 -0
  743. package/node_modules/pbkdf2/lib/sync.js +52 -0
  744. package/node_modules/pbkdf2/lib/to-buffer.js +13 -0
  745. package/node_modules/pbkdf2/package.json +74 -0
  746. package/node_modules/pump/.travis.yml +5 -0
  747. package/node_modules/pump/LICENSE +21 -0
  748. package/node_modules/pump/README.md +65 -0
  749. package/node_modules/pump/index.js +82 -0
  750. package/node_modules/pump/package.json +28 -0
  751. package/node_modules/pump/test-browser.js +66 -0
  752. package/node_modules/pump/test-node.js +53 -0
  753. package/node_modules/randombytes/.travis.yml +15 -0
  754. package/node_modules/randombytes/.zuul.yml +1 -0
  755. package/node_modules/randombytes/LICENSE +21 -0
  756. package/node_modules/randombytes/README.md +14 -0
  757. package/node_modules/randombytes/browser.js +50 -0
  758. package/node_modules/randombytes/index.js +1 -0
  759. package/node_modules/randombytes/package.json +40 -0
  760. package/node_modules/randombytes/test.js +81 -0
  761. package/node_modules/readable-stream/CONTRIBUTING.md +38 -0
  762. package/node_modules/readable-stream/GOVERNANCE.md +136 -0
  763. package/node_modules/readable-stream/LICENSE +47 -0
  764. package/node_modules/readable-stream/README.md +106 -0
  765. package/node_modules/readable-stream/errors-browser.js +127 -0
  766. package/node_modules/readable-stream/errors.js +116 -0
  767. package/node_modules/readable-stream/experimentalWarning.js +17 -0
  768. package/node_modules/readable-stream/lib/_stream_duplex.js +139 -0
  769. package/node_modules/readable-stream/lib/_stream_passthrough.js +39 -0
  770. package/node_modules/readable-stream/lib/_stream_readable.js +1124 -0
  771. package/node_modules/readable-stream/lib/_stream_transform.js +201 -0
  772. package/node_modules/readable-stream/lib/_stream_writable.js +697 -0
  773. package/node_modules/readable-stream/lib/internal/streams/async_iterator.js +207 -0
  774. package/node_modules/readable-stream/lib/internal/streams/buffer_list.js +210 -0
  775. package/node_modules/readable-stream/lib/internal/streams/destroy.js +105 -0
  776. package/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +104 -0
  777. package/node_modules/readable-stream/lib/internal/streams/from-browser.js +3 -0
  778. package/node_modules/readable-stream/lib/internal/streams/from.js +64 -0
  779. package/node_modules/readable-stream/lib/internal/streams/pipeline.js +97 -0
  780. package/node_modules/readable-stream/lib/internal/streams/state.js +27 -0
  781. package/node_modules/readable-stream/lib/internal/streams/stream-browser.js +1 -0
  782. package/node_modules/readable-stream/lib/internal/streams/stream.js +1 -0
  783. package/node_modules/readable-stream/package.json +72 -0
  784. package/node_modules/readable-stream/readable-browser.js +9 -0
  785. package/node_modules/readable-stream/readable.js +16 -0
  786. package/node_modules/require-directory/.jshintrc +67 -0
  787. package/node_modules/require-directory/.npmignore +1 -0
  788. package/node_modules/require-directory/.travis.yml +3 -0
  789. package/node_modules/require-directory/LICENSE +22 -0
  790. package/node_modules/require-directory/README.markdown +184 -0
  791. package/node_modules/require-directory/index.js +86 -0
  792. package/node_modules/require-directory/package.json +44 -0
  793. package/node_modules/require-main-filename/LICENSE.txt +14 -0
  794. package/node_modules/require-main-filename/README.md +26 -0
  795. package/node_modules/require-main-filename/index.js +18 -0
  796. package/node_modules/require-main-filename/package.json +39 -0
  797. package/node_modules/ripemd160/LICENSE +21 -0
  798. package/node_modules/ripemd160/README.md +27 -0
  799. package/node_modules/ripemd160/index.js +163 -0
  800. package/node_modules/ripemd160/package.json +41 -0
  801. package/node_modules/rlp/LICENSE +373 -0
  802. package/node_modules/rlp/README.md +58 -0
  803. package/node_modules/rlp/bin/rlp +35 -0
  804. package/node_modules/rlp/dist/index.d.ts +25 -0
  805. package/node_modules/rlp/dist/index.js +249 -0
  806. package/node_modules/rlp/dist/index.js.map +1 -0
  807. package/node_modules/rlp/dist/types.d.ts +9 -0
  808. package/node_modules/rlp/dist/types.js +3 -0
  809. package/node_modules/rlp/dist/types.js.map +1 -0
  810. package/node_modules/rlp/package.json +84 -0
  811. package/node_modules/safe-buffer/LICENSE +21 -0
  812. package/node_modules/safe-buffer/README.md +584 -0
  813. package/node_modules/safe-buffer/index.d.ts +187 -0
  814. package/node_modules/safe-buffer/index.js +65 -0
  815. package/node_modules/safe-buffer/package.json +55 -0
  816. package/node_modules/scrypt-js/LICENSE.txt +22 -0
  817. package/node_modules/scrypt-js/README.md +222 -0
  818. package/node_modules/scrypt-js/index.html +291 -0
  819. package/node_modules/scrypt-js/package.json +31 -0
  820. package/node_modules/scrypt-js/scrypt.d.ts +23 -0
  821. package/node_modules/scrypt-js/scrypt.js +488 -0
  822. package/node_modules/scrypt-js/thirdparty/buffer.js +1381 -0
  823. package/node_modules/scrypt-js/thirdparty/setImmediate.js +175 -0
  824. package/node_modules/scrypt-js/thirdparty/unorm.js +442 -0
  825. package/node_modules/secp256k1/API.md +116 -0
  826. package/node_modules/secp256k1/LICENSE +24 -0
  827. package/node_modules/secp256k1/README.md +117 -0
  828. package/node_modules/secp256k1/binding.gyp +100 -0
  829. package/node_modules/secp256k1/bindings.js +2 -0
  830. package/node_modules/secp256k1/elliptic.js +1 -0
  831. package/node_modules/secp256k1/index.js +5 -0
  832. package/node_modules/secp256k1/lib/elliptic.js +402 -0
  833. package/node_modules/secp256k1/lib/index.js +336 -0
  834. package/node_modules/secp256k1/package.json +47 -0
  835. package/node_modules/secp256k1/prebuilds/darwin-x64/node.napi.node +0 -0
  836. package/node_modules/secp256k1/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  837. package/node_modules/secp256k1/prebuilds/linux-x64/node.napi.musl.node +0 -0
  838. package/node_modules/secp256k1/prebuilds/win32-x64/node.napi.node +0 -0
  839. package/node_modules/secp256k1/src/addon.cc +10 -0
  840. package/node_modules/secp256k1/src/secp256k1/.travis.yml +100 -0
  841. package/node_modules/secp256k1/src/secp256k1/COPYING +19 -0
  842. package/node_modules/secp256k1/src/secp256k1/Makefile.am +183 -0
  843. package/node_modules/secp256k1/src/secp256k1/README.md +78 -0
  844. package/node_modules/secp256k1/src/secp256k1/SECURITY.md +15 -0
  845. package/node_modules/secp256k1/src/secp256k1/TODO +3 -0
  846. package/node_modules/secp256k1/src/secp256k1/autogen.sh +3 -0
  847. package/node_modules/secp256k1/src/secp256k1/build-aux/m4/ax_jni_include_dir.m4 +145 -0
  848. package/node_modules/secp256k1/src/secp256k1/build-aux/m4/ax_prog_cc_for_build.m4 +125 -0
  849. package/node_modules/secp256k1/src/secp256k1/build-aux/m4/bitcoin_secp.m4 +68 -0
  850. package/node_modules/secp256k1/src/secp256k1/configure.ac +591 -0
  851. package/node_modules/secp256k1/src/secp256k1/contrib/lax_der_parsing.c +150 -0
  852. package/node_modules/secp256k1/src/secp256k1/contrib/lax_der_parsing.h +91 -0
  853. package/node_modules/secp256k1/src/secp256k1/contrib/lax_der_privatekey_parsing.c +113 -0
  854. package/node_modules/secp256k1/src/secp256k1/contrib/lax_der_privatekey_parsing.h +90 -0
  855. package/node_modules/secp256k1/src/secp256k1/include/secp256k1.h +708 -0
  856. package/node_modules/secp256k1/src/secp256k1/include/secp256k1_ecdh.h +55 -0
  857. package/node_modules/secp256k1/src/secp256k1/include/secp256k1_preallocated.h +128 -0
  858. package/node_modules/secp256k1/src/secp256k1/include/secp256k1_recovery.h +110 -0
  859. package/node_modules/secp256k1/src/secp256k1/libsecp256k1.pc.in +13 -0
  860. package/node_modules/secp256k1/src/secp256k1/sage/group_prover.sage +322 -0
  861. package/node_modules/secp256k1/src/secp256k1/sage/secp256k1.sage +306 -0
  862. package/node_modules/secp256k1/src/secp256k1/sage/weierstrass_prover.sage +264 -0
  863. package/node_modules/secp256k1/src/secp256k1/src/asm/field_10x26_arm.s +913 -0
  864. package/node_modules/secp256k1/src/secp256k1/src/basic-config.h +38 -0
  865. package/node_modules/secp256k1/src/secp256k1/src/bench.h +124 -0
  866. package/node_modules/secp256k1/src/secp256k1/src/bench_ecdh.c +54 -0
  867. package/node_modules/secp256k1/src/secp256k1/src/bench_ecmult.c +207 -0
  868. package/node_modules/secp256k1/src/secp256k1/src/bench_internal.c +379 -0
  869. package/node_modules/secp256k1/src/secp256k1/src/bench_recover.c +60 -0
  870. package/node_modules/secp256k1/src/secp256k1/src/bench_sign.c +56 -0
  871. package/node_modules/secp256k1/src/secp256k1/src/bench_verify.c +112 -0
  872. package/node_modules/secp256k1/src/secp256k1/src/ecdsa.h +21 -0
  873. package/node_modules/secp256k1/src/secp256k1/src/ecdsa_impl.h +319 -0
  874. package/node_modules/secp256k1/src/secp256k1/src/eckey.h +25 -0
  875. package/node_modules/secp256k1/src/secp256k1/src/eckey_impl.h +100 -0
  876. package/node_modules/secp256k1/src/secp256k1/src/ecmult.h +48 -0
  877. package/node_modules/secp256k1/src/secp256k1/src/ecmult_const.h +20 -0
  878. package/node_modules/secp256k1/src/secp256k1/src/ecmult_const_impl.h +261 -0
  879. package/node_modules/secp256k1/src/secp256k1/src/ecmult_gen.h +50 -0
  880. package/node_modules/secp256k1/src/secp256k1/src/ecmult_gen_impl.h +211 -0
  881. package/node_modules/secp256k1/src/secp256k1/src/ecmult_impl.h +1216 -0
  882. package/node_modules/secp256k1/src/secp256k1/src/field.h +132 -0
  883. package/node_modules/secp256k1/src/secp256k1/src/field_10x26.h +50 -0
  884. package/node_modules/secp256k1/src/secp256k1/src/field_10x26_impl.h +1162 -0
  885. package/node_modules/secp256k1/src/secp256k1/src/field_5x52.h +49 -0
  886. package/node_modules/secp256k1/src/secp256k1/src/field_5x52_asm_impl.h +502 -0
  887. package/node_modules/secp256k1/src/secp256k1/src/field_5x52_impl.h +496 -0
  888. package/node_modules/secp256k1/src/secp256k1/src/field_5x52_int128_impl.h +279 -0
  889. package/node_modules/secp256k1/src/secp256k1/src/field_impl.h +318 -0
  890. package/node_modules/secp256k1/src/secp256k1/src/gen_context.c +87 -0
  891. package/node_modules/secp256k1/src/secp256k1/src/group.h +142 -0
  892. package/node_modules/secp256k1/src/secp256k1/src/group_impl.h +705 -0
  893. package/node_modules/secp256k1/src/secp256k1/src/hash.h +41 -0
  894. package/node_modules/secp256k1/src/secp256k1/src/hash_impl.h +283 -0
  895. package/node_modules/secp256k1/src/secp256k1/src/java/org/bitcoin/NativeSecp256k1.java +446 -0
  896. package/node_modules/secp256k1/src/secp256k1/src/java/org/bitcoin/NativeSecp256k1Test.java +225 -0
  897. package/node_modules/secp256k1/src/secp256k1/src/java/org/bitcoin/NativeSecp256k1Util.java +45 -0
  898. package/node_modules/secp256k1/src/secp256k1/src/java/org/bitcoin/Secp256k1Context.java +51 -0
  899. package/node_modules/secp256k1/src/secp256k1/src/java/org_bitcoin_NativeSecp256k1.c +379 -0
  900. package/node_modules/secp256k1/src/secp256k1/src/java/org_bitcoin_NativeSecp256k1.h +119 -0
  901. package/node_modules/secp256k1/src/secp256k1/src/java/org_bitcoin_Secp256k1Context.c +15 -0
  902. package/node_modules/secp256k1/src/secp256k1/src/java/org_bitcoin_Secp256k1Context.h +22 -0
  903. package/node_modules/secp256k1/src/secp256k1/src/modules/ecdh/Makefile.am.include +8 -0
  904. package/node_modules/secp256k1/src/secp256k1/src/modules/ecdh/main_impl.h +67 -0
  905. package/node_modules/secp256k1/src/secp256k1/src/modules/ecdh/tests_impl.h +132 -0
  906. package/node_modules/secp256k1/src/secp256k1/src/modules/recovery/Makefile.am.include +8 -0
  907. package/node_modules/secp256k1/src/secp256k1/src/modules/recovery/main_impl.h +193 -0
  908. package/node_modules/secp256k1/src/secp256k1/src/modules/recovery/tests_impl.h +393 -0
  909. package/node_modules/secp256k1/src/secp256k1/src/num.h +74 -0
  910. package/node_modules/secp256k1/src/secp256k1/src/num_gmp.h +20 -0
  911. package/node_modules/secp256k1/src/secp256k1/src/num_gmp_impl.h +288 -0
  912. package/node_modules/secp256k1/src/secp256k1/src/num_impl.h +24 -0
  913. package/node_modules/secp256k1/src/secp256k1/src/scalar.h +106 -0
  914. package/node_modules/secp256k1/src/secp256k1/src/scalar_4x64.h +19 -0
  915. package/node_modules/secp256k1/src/secp256k1/src/scalar_4x64_impl.h +949 -0
  916. package/node_modules/secp256k1/src/secp256k1/src/scalar_8x32.h +19 -0
  917. package/node_modules/secp256k1/src/secp256k1/src/scalar_8x32_impl.h +721 -0
  918. package/node_modules/secp256k1/src/secp256k1/src/scalar_impl.h +333 -0
  919. package/node_modules/secp256k1/src/secp256k1/src/scalar_low.h +15 -0
  920. package/node_modules/secp256k1/src/secp256k1/src/scalar_low_impl.h +117 -0
  921. package/node_modules/secp256k1/src/secp256k1/src/scratch.h +42 -0
  922. package/node_modules/secp256k1/src/secp256k1/src/scratch_impl.h +88 -0
  923. package/node_modules/secp256k1/src/secp256k1/src/secp256k1.c +690 -0
  924. package/node_modules/secp256k1/src/secp256k1/src/testrand.h +38 -0
  925. package/node_modules/secp256k1/src/secp256k1/src/testrand_impl.h +110 -0
  926. package/node_modules/secp256k1/src/secp256k1/src/tests.c +5310 -0
  927. package/node_modules/secp256k1/src/secp256k1/src/tests_exhaustive.c +511 -0
  928. package/node_modules/secp256k1/src/secp256k1/src/util.h +162 -0
  929. package/node_modules/secp256k1/src/secp256k1.cc +415 -0
  930. package/node_modules/secp256k1/src/secp256k1.h +63 -0
  931. package/node_modules/semver/LICENSE +15 -0
  932. package/node_modules/semver/README.md +412 -0
  933. package/node_modules/semver/bin/semver +160 -0
  934. package/node_modules/semver/package.json +32 -0
  935. package/node_modules/semver/range.bnf +16 -0
  936. package/node_modules/semver/semver.js +1483 -0
  937. package/node_modules/set-blocking/LICENSE.txt +14 -0
  938. package/node_modules/set-blocking/README.md +31 -0
  939. package/node_modules/set-blocking/index.js +7 -0
  940. package/node_modules/set-blocking/package.json +46 -0
  941. package/node_modules/setimmediate/LICENSE.txt +20 -0
  942. package/node_modules/setimmediate/package.json +34 -0
  943. package/node_modules/setimmediate/setImmediate.js +186 -0
  944. package/node_modules/sha.js/.travis.yml +17 -0
  945. package/node_modules/sha.js/LICENSE +49 -0
  946. package/node_modules/sha.js/README.md +44 -0
  947. package/node_modules/sha.js/bin.js +41 -0
  948. package/node_modules/sha.js/hash.js +81 -0
  949. package/node_modules/sha.js/index.js +15 -0
  950. package/node_modules/sha.js/package.json +34 -0
  951. package/node_modules/sha.js/sha.js +94 -0
  952. package/node_modules/sha.js/sha1.js +99 -0
  953. package/node_modules/sha.js/sha224.js +53 -0
  954. package/node_modules/sha.js/sha256.js +135 -0
  955. package/node_modules/sha.js/sha384.js +57 -0
  956. package/node_modules/sha.js/sha512.js +260 -0
  957. package/node_modules/sha.js/test/hash.js +75 -0
  958. package/node_modules/sha.js/test/test.js +100 -0
  959. package/node_modules/sha.js/test/vectors.js +72 -0
  960. package/node_modules/shebang-command/index.js +19 -0
  961. package/node_modules/shebang-command/license +21 -0
  962. package/node_modules/shebang-command/package.json +43 -0
  963. package/node_modules/shebang-command/readme.md +39 -0
  964. package/node_modules/shebang-regex/index.js +2 -0
  965. package/node_modules/shebang-regex/license +21 -0
  966. package/node_modules/shebang-regex/package.json +36 -0
  967. package/node_modules/shebang-regex/readme.md +29 -0
  968. package/node_modules/signal-exit/LICENSE.txt +16 -0
  969. package/node_modules/signal-exit/README.md +39 -0
  970. package/node_modules/signal-exit/index.js +163 -0
  971. package/node_modules/signal-exit/package.json +42 -0
  972. package/node_modules/signal-exit/signals.js +53 -0
  973. package/node_modules/source-map/LICENSE +28 -0
  974. package/node_modules/source-map/README.md +742 -0
  975. package/node_modules/source-map/dist/source-map.debug.js +3234 -0
  976. package/node_modules/source-map/dist/source-map.js +3233 -0
  977. package/node_modules/source-map/dist/source-map.min.js +2 -0
  978. package/node_modules/source-map/dist/source-map.min.js.map +1 -0
  979. package/node_modules/source-map/lib/array-set.js +121 -0
  980. package/node_modules/source-map/lib/base64-vlq.js +140 -0
  981. package/node_modules/source-map/lib/base64.js +67 -0
  982. package/node_modules/source-map/lib/binary-search.js +111 -0
  983. package/node_modules/source-map/lib/mapping-list.js +79 -0
  984. package/node_modules/source-map/lib/quick-sort.js +114 -0
  985. package/node_modules/source-map/lib/source-map-consumer.js +1145 -0
  986. package/node_modules/source-map/lib/source-map-generator.js +425 -0
  987. package/node_modules/source-map/lib/source-node.js +413 -0
  988. package/node_modules/source-map/lib/util.js +488 -0
  989. package/node_modules/source-map/package.json +77 -0
  990. package/node_modules/source-map/source-map.d.ts +98 -0
  991. package/node_modules/source-map/source-map.js +8 -0
  992. package/node_modules/source-map-support/LICENSE.md +21 -0
  993. package/node_modules/source-map-support/README.md +284 -0
  994. package/node_modules/source-map-support/browser-source-map-support.js +113 -0
  995. package/node_modules/source-map-support/package.json +35 -0
  996. package/node_modules/source-map-support/register.js +1 -0
  997. package/node_modules/source-map-support/source-map-support.js +567 -0
  998. package/node_modules/string-width/index.js +39 -0
  999. package/node_modules/string-width/license +9 -0
  1000. package/node_modules/string-width/package.json +60 -0
  1001. package/node_modules/string-width/readme.md +45 -0
  1002. package/node_modules/string_decoder/LICENSE +48 -0
  1003. package/node_modules/string_decoder/README.md +47 -0
  1004. package/node_modules/string_decoder/lib/string_decoder.js +296 -0
  1005. package/node_modules/string_decoder/package.json +38 -0
  1006. package/node_modules/strip-ansi/index.d.ts +15 -0
  1007. package/node_modules/strip-ansi/index.js +7 -0
  1008. package/node_modules/strip-ansi/license +9 -0
  1009. package/node_modules/strip-ansi/package.json +58 -0
  1010. package/node_modules/strip-ansi/readme.md +61 -0
  1011. package/node_modules/strip-eof/index.js +15 -0
  1012. package/node_modules/strip-eof/license +21 -0
  1013. package/node_modules/strip-eof/package.json +43 -0
  1014. package/node_modules/strip-eof/readme.md +28 -0
  1015. package/node_modules/strip-hex-prefix/.editorconfig +7 -0
  1016. package/node_modules/strip-hex-prefix/.gitattributes +106 -0
  1017. package/node_modules/strip-hex-prefix/.npmignore +8 -0
  1018. package/node_modules/strip-hex-prefix/.travis.yml +5 -0
  1019. package/node_modules/strip-hex-prefix/CHANGELOG.md +7 -0
  1020. package/node_modules/strip-hex-prefix/LICENSE +21 -0
  1021. package/node_modules/strip-hex-prefix/README.md +106 -0
  1022. package/node_modules/strip-hex-prefix/package.json +46 -0
  1023. package/node_modules/strip-hex-prefix/src/index.js +14 -0
  1024. package/node_modules/strip-hex-prefix/src/tests/test.index.js +47 -0
  1025. package/node_modules/util-deprecate/History.md +16 -0
  1026. package/node_modules/util-deprecate/LICENSE +24 -0
  1027. package/node_modules/util-deprecate/README.md +53 -0
  1028. package/node_modules/util-deprecate/browser.js +67 -0
  1029. package/node_modules/util-deprecate/node.js +6 -0
  1030. package/node_modules/util-deprecate/package.json +31 -0
  1031. package/node_modules/which/LICENSE +15 -0
  1032. package/node_modules/which/README.md +51 -0
  1033. package/node_modules/which/bin/which +52 -0
  1034. package/node_modules/which/package.json +34 -0
  1035. package/node_modules/which/which.js +135 -0
  1036. package/node_modules/which-module/LICENSE +13 -0
  1037. package/node_modules/which-module/README.md +55 -0
  1038. package/node_modules/which-module/index.js +9 -0
  1039. package/node_modules/which-module/package.json +45 -0
  1040. package/node_modules/wrap-ansi/index.js +188 -0
  1041. package/node_modules/wrap-ansi/license +9 -0
  1042. package/node_modules/wrap-ansi/package.json +65 -0
  1043. package/node_modules/wrap-ansi/readme.md +108 -0
  1044. package/node_modules/wrappy/LICENSE +15 -0
  1045. package/node_modules/wrappy/README.md +36 -0
  1046. package/node_modules/wrappy/package.json +33 -0
  1047. package/node_modules/wrappy/wrappy.js +33 -0
  1048. package/node_modules/y18n/LICENSE +13 -0
  1049. package/node_modules/y18n/README.md +109 -0
  1050. package/node_modules/y18n/index.js +188 -0
  1051. package/node_modules/y18n/package.json +43 -0
  1052. package/node_modules/yargs/LICENSE +22 -0
  1053. package/node_modules/yargs/README.md +122 -0
  1054. package/node_modules/yargs/index.js +32 -0
  1055. package/node_modules/yargs/lib/apply-extends.js +53 -0
  1056. package/node_modules/yargs/lib/argsert.js +68 -0
  1057. package/node_modules/yargs/lib/command.js +437 -0
  1058. package/node_modules/yargs/lib/completion-templates.js +49 -0
  1059. package/node_modules/yargs/lib/completion.js +115 -0
  1060. package/node_modules/yargs/lib/decamelize.js +32 -0
  1061. package/node_modules/yargs/lib/is-promise.js +3 -0
  1062. package/node_modules/yargs/lib/levenshtein.js +58 -0
  1063. package/node_modules/yargs/lib/middleware.js +65 -0
  1064. package/node_modules/yargs/lib/obj-filter.js +11 -0
  1065. package/node_modules/yargs/lib/usage.js +540 -0
  1066. package/node_modules/yargs/lib/validation.js +341 -0
  1067. package/node_modules/yargs/lib/yerror.js +11 -0
  1068. package/node_modules/yargs/locales/be.json +39 -0
  1069. package/node_modules/yargs/locales/de.json +39 -0
  1070. package/node_modules/yargs/locales/en.json +42 -0
  1071. package/node_modules/yargs/locales/es.json +39 -0
  1072. package/node_modules/yargs/locales/fr.json +37 -0
  1073. package/node_modules/yargs/locales/hi.json +42 -0
  1074. package/node_modules/yargs/locales/hu.json +39 -0
  1075. package/node_modules/yargs/locales/id.json +43 -0
  1076. package/node_modules/yargs/locales/it.json +39 -0
  1077. package/node_modules/yargs/locales/ja.json +42 -0
  1078. package/node_modules/yargs/locales/ko.json +42 -0
  1079. package/node_modules/yargs/locales/nb.json +37 -0
  1080. package/node_modules/yargs/locales/nl.json +42 -0
  1081. package/node_modules/yargs/locales/nn.json +39 -0
  1082. package/node_modules/yargs/locales/pirate.json +13 -0
  1083. package/node_modules/yargs/locales/pl.json +42 -0
  1084. package/node_modules/yargs/locales/pt.json +38 -0
  1085. package/node_modules/yargs/locales/pt_BR.json +42 -0
  1086. package/node_modules/yargs/locales/ru.json +39 -0
  1087. package/node_modules/yargs/locales/th.json +39 -0
  1088. package/node_modules/yargs/locales/tr.json +41 -0
  1089. package/node_modules/yargs/locales/zh_CN.json +41 -0
  1090. package/node_modules/yargs/locales/zh_TW.json +40 -0
  1091. package/node_modules/yargs/package.json +83 -0
  1092. package/node_modules/yargs/yargs.js +1205 -0
  1093. package/node_modules/yargs-parser/LICENSE.txt +14 -0
  1094. package/node_modules/yargs-parser/README.md +396 -0
  1095. package/node_modules/yargs-parser/index.js +916 -0
  1096. package/node_modules/yargs-parser/lib/tokenize-arg-string.js +40 -0
  1097. package/node_modules/yargs-parser/package.json +51 -0
  1098. package/package.json +73 -4
@@ -0,0 +1,3655 @@
1
+ /******************************************************************************
2
+ * Experimental prototype for demonstrating VM agnostic and ABI stable API
3
+ * for native modules to use instead of using Nan and V8 APIs directly.
4
+ *
5
+ * The current status is "Experimental" and should not be used for
6
+ * production applications. The API is still subject to change
7
+ * and as an experimental feature is NOT subject to semver.
8
+ *
9
+ ******************************************************************************/
10
+
11
+ #include <node_buffer.h>
12
+ #include <node_object_wrap.h>
13
+ #include <limits.h> // INT_MAX
14
+ #include <string.h>
15
+ #include <algorithm>
16
+ #include <cmath>
17
+ #include <vector>
18
+ #include "node_api.h"
19
+ #include "node_internals.h"
20
+
21
+ #define NAPI_VERSION 1
22
+
23
+ static
24
+ napi_status napi_set_last_error(napi_env env, napi_status error_code,
25
+ uint32_t engine_error_code = 0,
26
+ void* engine_reserved = nullptr);
27
+ static
28
+ napi_status napi_clear_last_error(napi_env env);
29
+
30
+ struct napi_env__ {
31
+ explicit napi_env__(v8::Isolate* _isolate): isolate(_isolate),
32
+ has_instance_available(true), last_error() {}
33
+ ~napi_env__() {
34
+ last_exception.Reset();
35
+ has_instance.Reset();
36
+ wrap_template.Reset();
37
+ }
38
+ v8::Isolate* isolate;
39
+ v8::Persistent<v8::Value> last_exception;
40
+ v8::Persistent<v8::Value> has_instance;
41
+ v8::Persistent<v8::ObjectTemplate> wrap_template;
42
+ bool has_instance_available;
43
+ napi_extended_error_info last_error;
44
+ int open_handle_scopes = 0;
45
+ };
46
+
47
+ #define ENV_OBJECT_TEMPLATE(env, prefix, destination, field_count) \
48
+ do { \
49
+ if ((env)->prefix ## _template.IsEmpty()) { \
50
+ (destination) = v8::ObjectTemplate::New(isolate); \
51
+ (destination)->SetInternalFieldCount((field_count)); \
52
+ (env)->prefix ## _template.Reset(isolate, (destination)); \
53
+ } else { \
54
+ (destination) = v8::Local<v8::ObjectTemplate>::New( \
55
+ isolate, env->prefix ## _template); \
56
+ } \
57
+ } while (0)
58
+
59
+ #define RETURN_STATUS_IF_FALSE(env, condition, status) \
60
+ do { \
61
+ if (!(condition)) { \
62
+ return napi_set_last_error((env), (status)); \
63
+ } \
64
+ } while (0)
65
+
66
+ #define CHECK_ENV(env) \
67
+ if ((env) == nullptr) { \
68
+ return napi_invalid_arg; \
69
+ }
70
+
71
+ #define CHECK_ARG(env, arg) \
72
+ RETURN_STATUS_IF_FALSE((env), ((arg) != nullptr), napi_invalid_arg)
73
+
74
+ #define CHECK_MAYBE_EMPTY(env, maybe, status) \
75
+ RETURN_STATUS_IF_FALSE((env), !((maybe).IsEmpty()), (status))
76
+
77
+ #define CHECK_MAYBE_NOTHING(env, maybe, status) \
78
+ RETURN_STATUS_IF_FALSE((env), !((maybe).IsNothing()), (status))
79
+
80
+ // NAPI_PREAMBLE is not wrapped in do..while: try_catch must have function scope
81
+ #define NAPI_PREAMBLE(env) \
82
+ CHECK_ENV((env)); \
83
+ RETURN_STATUS_IF_FALSE((env), (env)->last_exception.IsEmpty(), \
84
+ napi_pending_exception); \
85
+ napi_clear_last_error((env)); \
86
+ v8impl::TryCatch try_catch((env))
87
+
88
+ #define CHECK_TO_TYPE(env, type, context, result, src, status) \
89
+ do { \
90
+ CHECK_ARG((env), (src)); \
91
+ auto maybe = v8impl::V8LocalValueFromJsValue((src))->To##type((context)); \
92
+ CHECK_MAYBE_EMPTY((env), maybe, (status)); \
93
+ (result) = maybe.ToLocalChecked(); \
94
+ } while (0)
95
+
96
+ #define CHECK_TO_FUNCTION(env, result, src) \
97
+ do { \
98
+ CHECK_ARG((env), (src)); \
99
+ v8::Local<v8::Value> v8value = v8impl::V8LocalValueFromJsValue((src)); \
100
+ RETURN_STATUS_IF_FALSE((env), v8value->IsFunction(), napi_invalid_arg); \
101
+ (result) = v8value.As<v8::Function>(); \
102
+ } while (0)
103
+
104
+ #define CHECK_TO_OBJECT(env, context, result, src) \
105
+ CHECK_TO_TYPE((env), Object, (context), (result), (src), napi_object_expected)
106
+
107
+ #define CHECK_TO_STRING(env, context, result, src) \
108
+ CHECK_TO_TYPE((env), String, (context), (result), (src), napi_string_expected)
109
+
110
+ #define CHECK_TO_NUMBER(env, context, result, src) \
111
+ CHECK_TO_TYPE((env), Number, (context), (result), (src), napi_number_expected)
112
+
113
+ #define CHECK_TO_BOOL(env, context, result, src) \
114
+ CHECK_TO_TYPE((env), Boolean, (context), (result), (src), \
115
+ napi_boolean_expected)
116
+
117
+ // n-api defines NAPI_AUTO_LENGHTH as the indicator that a string
118
+ // is null terminated. For V8 the equivalent is -1. The assert
119
+ // validates that our cast of NAPI_AUTO_LENGTH results in -1 as
120
+ // needed by V8.
121
+ #define CHECK_NEW_FROM_UTF8_LEN(env, result, str, len) \
122
+ do { \
123
+ static_assert(static_cast<int>(NAPI_AUTO_LENGTH) == -1, \
124
+ "Casting NAPI_AUTO_LENGTH to int must result in -1"); \
125
+ RETURN_STATUS_IF_FALSE((env), \
126
+ (len == NAPI_AUTO_LENGTH) || len <= INT_MAX, \
127
+ napi_invalid_arg); \
128
+ auto str_maybe = v8::String::NewFromUtf8( \
129
+ (env)->isolate, (str), v8::NewStringType::kInternalized, \
130
+ static_cast<int>(len)); \
131
+ CHECK_MAYBE_EMPTY((env), str_maybe, napi_generic_failure); \
132
+ (result) = str_maybe.ToLocalChecked(); \
133
+ } while (0)
134
+
135
+ #define CHECK_NEW_FROM_UTF8(env, result, str) \
136
+ CHECK_NEW_FROM_UTF8_LEN((env), (result), (str), NAPI_AUTO_LENGTH)
137
+
138
+ #define GET_RETURN_STATUS(env) \
139
+ (!try_catch.HasCaught() ? napi_ok \
140
+ : napi_set_last_error((env), napi_pending_exception))
141
+
142
+ #define THROW_RANGE_ERROR_IF_FALSE(env, condition, error, message) \
143
+ do { \
144
+ if (!(condition)) { \
145
+ napi_throw_range_error((env), (error), (message)); \
146
+ return napi_set_last_error((env), napi_generic_failure); \
147
+ } \
148
+ } while (0)
149
+
150
+ #define CREATE_TYPED_ARRAY( \
151
+ env, type, size_of_element, buffer, byte_offset, length, out) \
152
+ do { \
153
+ if ((size_of_element) > 1) { \
154
+ THROW_RANGE_ERROR_IF_FALSE( \
155
+ (env), (byte_offset) % (size_of_element) == 0, \
156
+ "ERR_NAPI_INVALID_TYPEDARRAY_ALIGNMENT", \
157
+ "start offset of "#type" should be a multiple of "#size_of_element); \
158
+ } \
159
+ THROW_RANGE_ERROR_IF_FALSE((env), (length) * (size_of_element) + \
160
+ (byte_offset) <= buffer->ByteLength(), \
161
+ "ERR_NAPI_INVALID_TYPEDARRAY_LENGTH", \
162
+ "Invalid typed array length"); \
163
+ (out) = v8::type::New((buffer), (byte_offset), (length)); \
164
+ } while (0)
165
+
166
+ #define NAPI_CALL_INTO_MODULE(env, call, handle_exception) \
167
+ do { \
168
+ int open_handle_scopes = (env)->open_handle_scopes; \
169
+ napi_clear_last_error((env)); \
170
+ call; \
171
+ CHECK_EQ((env)->open_handle_scopes, open_handle_scopes); \
172
+ if (!(env)->last_exception.IsEmpty()) { \
173
+ handle_exception( \
174
+ v8::Local<v8::Value>::New((env)->isolate, (env)->last_exception)); \
175
+ (env)->last_exception.Reset(); \
176
+ } \
177
+ } while (0)
178
+
179
+ #define NAPI_CALL_INTO_MODULE_THROW(env, call) \
180
+ NAPI_CALL_INTO_MODULE((env), call, (env)->isolate->ThrowException)
181
+
182
+ namespace {
183
+ namespace v8impl {
184
+
185
+ // convert from n-api property attributes to v8::PropertyAttribute
186
+ static inline v8::PropertyAttribute V8PropertyAttributesFromDescriptor(
187
+ const napi_property_descriptor* descriptor) {
188
+ unsigned int attribute_flags = v8::PropertyAttribute::None;
189
+
190
+ if (descriptor->getter != nullptr || descriptor->setter != nullptr) {
191
+ // The napi_writable attribute is ignored for accessor descriptors, but
192
+ // V8 requires the ReadOnly attribute to match nonexistence of a setter.
193
+ attribute_flags |= (descriptor->setter == nullptr ?
194
+ v8::PropertyAttribute::ReadOnly : v8::PropertyAttribute::None);
195
+ } else if ((descriptor->attributes & napi_writable) == 0) {
196
+ attribute_flags |= v8::PropertyAttribute::ReadOnly;
197
+ }
198
+
199
+ if ((descriptor->attributes & napi_enumerable) == 0) {
200
+ attribute_flags |= v8::PropertyAttribute::DontEnum;
201
+ }
202
+ if ((descriptor->attributes & napi_configurable) == 0) {
203
+ attribute_flags |= v8::PropertyAttribute::DontDelete;
204
+ }
205
+
206
+ return static_cast<v8::PropertyAttribute>(attribute_flags);
207
+ }
208
+
209
+ class HandleScopeWrapper {
210
+ public:
211
+ explicit HandleScopeWrapper(v8::Isolate* isolate) : scope(isolate) {}
212
+
213
+ private:
214
+ v8::HandleScope scope;
215
+ };
216
+
217
+ // In node v0.10 version of v8, there is no EscapableHandleScope and the
218
+ // node v0.10 port use HandleScope::Close(Local<T> v) to mimic the behavior
219
+ // of a EscapableHandleScope::Escape(Local<T> v), but it is not the same
220
+ // semantics. This is an example of where the api abstraction fail to work
221
+ // across different versions.
222
+ class EscapableHandleScopeWrapper {
223
+ public:
224
+ explicit EscapableHandleScopeWrapper(v8::Isolate* isolate)
225
+ : scope(isolate), escape_called_(false) {}
226
+ bool escape_called() const {
227
+ return escape_called_;
228
+ }
229
+ template <typename T>
230
+ v8::Local<T> Escape(v8::Local<T> handle) {
231
+ escape_called_ = true;
232
+ return scope.Escape(handle);
233
+ }
234
+
235
+ private:
236
+ v8::EscapableHandleScope scope;
237
+ bool escape_called_;
238
+ };
239
+
240
+ static
241
+ napi_handle_scope JsHandleScopeFromV8HandleScope(HandleScopeWrapper* s) {
242
+ return reinterpret_cast<napi_handle_scope>(s);
243
+ }
244
+
245
+ static
246
+ HandleScopeWrapper* V8HandleScopeFromJsHandleScope(napi_handle_scope s) {
247
+ return reinterpret_cast<HandleScopeWrapper*>(s);
248
+ }
249
+
250
+ static
251
+ napi_escapable_handle_scope JsEscapableHandleScopeFromV8EscapableHandleScope(
252
+ EscapableHandleScopeWrapper* s) {
253
+ return reinterpret_cast<napi_escapable_handle_scope>(s);
254
+ }
255
+
256
+ static
257
+ EscapableHandleScopeWrapper*
258
+ V8EscapableHandleScopeFromJsEscapableHandleScope(
259
+ napi_escapable_handle_scope s) {
260
+ return reinterpret_cast<EscapableHandleScopeWrapper*>(s);
261
+ }
262
+
263
+ //=== Conversion between V8 Handles and napi_value ========================
264
+
265
+ // This asserts v8::Local<> will always be implemented with a single
266
+ // pointer field so that we can pass it around as a void*.
267
+ static_assert(sizeof(v8::Local<v8::Value>) == sizeof(napi_value),
268
+ "Cannot convert between v8::Local<v8::Value> and napi_value");
269
+
270
+ static
271
+ napi_deferred JsDeferredFromV8Persistent(v8::Persistent<v8::Value>* local) {
272
+ return reinterpret_cast<napi_deferred>(local);
273
+ }
274
+
275
+ static
276
+ v8::Persistent<v8::Value>* V8PersistentFromJsDeferred(napi_deferred local) {
277
+ return reinterpret_cast<v8::Persistent<v8::Value>*>(local);
278
+ }
279
+
280
+ static
281
+ napi_value JsValueFromV8LocalValue(v8::Local<v8::Value> local) {
282
+ return reinterpret_cast<napi_value>(*local);
283
+ }
284
+
285
+ static
286
+ v8::Local<v8::Value> V8LocalValueFromJsValue(napi_value v) {
287
+ v8::Local<v8::Value> local;
288
+ memcpy(&local, &v, sizeof(v));
289
+ return local;
290
+ }
291
+
292
+ static inline void trigger_fatal_exception(
293
+ napi_env env, v8::Local<v8::Value> local_err) {
294
+ v8::TryCatch try_catch(env->isolate);
295
+ env->isolate->ThrowException(local_err);
296
+ node::FatalException(env->isolate, try_catch);
297
+ }
298
+
299
+ static inline napi_status V8NameFromPropertyDescriptor(napi_env env,
300
+ const napi_property_descriptor* p,
301
+ v8::Local<v8::Name>* result) {
302
+ if (p->utf8name != nullptr) {
303
+ CHECK_NEW_FROM_UTF8(env, *result, p->utf8name);
304
+ } else {
305
+ v8::Local<v8::Value> property_value =
306
+ v8impl::V8LocalValueFromJsValue(p->name);
307
+
308
+ RETURN_STATUS_IF_FALSE(env, property_value->IsName(), napi_name_expected);
309
+ *result = property_value.As<v8::Name>();
310
+ }
311
+
312
+ return napi_ok;
313
+ }
314
+
315
+ // Adapter for napi_finalize callbacks.
316
+ class Finalizer {
317
+ protected:
318
+ Finalizer(napi_env env,
319
+ napi_finalize finalize_callback,
320
+ void* finalize_data,
321
+ void* finalize_hint)
322
+ : _env(env),
323
+ _finalize_callback(finalize_callback),
324
+ _finalize_data(finalize_data),
325
+ _finalize_hint(finalize_hint) {
326
+ }
327
+
328
+ ~Finalizer() {
329
+ }
330
+
331
+ public:
332
+ static Finalizer* New(napi_env env,
333
+ napi_finalize finalize_callback = nullptr,
334
+ void* finalize_data = nullptr,
335
+ void* finalize_hint = nullptr) {
336
+ return new Finalizer(
337
+ env, finalize_callback, finalize_data, finalize_hint);
338
+ }
339
+
340
+ static void Delete(Finalizer* finalizer) {
341
+ delete finalizer;
342
+ }
343
+
344
+ // node::Buffer::FreeCallback
345
+ static void FinalizeBufferCallback(char* data, void* hint) {
346
+ Finalizer* finalizer = static_cast<Finalizer*>(hint);
347
+ if (finalizer->_finalize_callback != nullptr) {
348
+ NAPI_CALL_INTO_MODULE_THROW(finalizer->_env,
349
+ finalizer->_finalize_callback(
350
+ finalizer->_env,
351
+ data,
352
+ finalizer->_finalize_hint));
353
+ }
354
+
355
+ Delete(finalizer);
356
+ }
357
+
358
+ protected:
359
+ napi_env _env;
360
+ napi_finalize _finalize_callback;
361
+ void* _finalize_data;
362
+ void* _finalize_hint;
363
+ };
364
+
365
+ // Wrapper around v8::Persistent that implements reference counting.
366
+ class Reference : private Finalizer {
367
+ private:
368
+ Reference(napi_env env,
369
+ v8::Local<v8::Value> value,
370
+ uint32_t initial_refcount,
371
+ bool delete_self,
372
+ napi_finalize finalize_callback,
373
+ void* finalize_data,
374
+ void* finalize_hint)
375
+ : Finalizer(env, finalize_callback, finalize_data, finalize_hint),
376
+ _persistent(env->isolate, value),
377
+ _refcount(initial_refcount),
378
+ _delete_self(delete_self) {
379
+ if (initial_refcount == 0) {
380
+ _persistent.SetWeak(
381
+ this, FinalizeCallback, v8::WeakCallbackType::kParameter);
382
+ _persistent.MarkIndependent();
383
+ }
384
+ }
385
+
386
+ ~Reference() {
387
+ // The V8 Persistent class currently does not reset in its destructor:
388
+ // see NonCopyablePersistentTraits::kResetInDestructor = false.
389
+ // (Comments there claim that might change in the future.)
390
+ // To avoid memory leaks, it is better to reset at this time, however
391
+ // care must be taken to avoid attempting this after the Isolate has
392
+ // shut down, for example via a static (atexit) destructor.
393
+ _persistent.Reset();
394
+ }
395
+
396
+ public:
397
+ static Reference* New(napi_env env,
398
+ v8::Local<v8::Value> value,
399
+ uint32_t initial_refcount,
400
+ bool delete_self,
401
+ napi_finalize finalize_callback = nullptr,
402
+ void* finalize_data = nullptr,
403
+ void* finalize_hint = nullptr) {
404
+ return new Reference(env,
405
+ value,
406
+ initial_refcount,
407
+ delete_self,
408
+ finalize_callback,
409
+ finalize_data,
410
+ finalize_hint);
411
+ }
412
+
413
+ static void Delete(Reference* reference) {
414
+ delete reference;
415
+ }
416
+
417
+ uint32_t Ref() {
418
+ if (++_refcount == 1) {
419
+ _persistent.ClearWeak();
420
+ }
421
+
422
+ return _refcount;
423
+ }
424
+
425
+ uint32_t Unref() {
426
+ if (_refcount == 0) {
427
+ return 0;
428
+ }
429
+ if (--_refcount == 0) {
430
+ _persistent.SetWeak(
431
+ this, FinalizeCallback, v8::WeakCallbackType::kParameter);
432
+ _persistent.MarkIndependent();
433
+ }
434
+
435
+ return _refcount;
436
+ }
437
+
438
+ uint32_t RefCount() {
439
+ return _refcount;
440
+ }
441
+
442
+ v8::Local<v8::Value> Get() {
443
+ if (_persistent.IsEmpty()) {
444
+ return v8::Local<v8::Value>();
445
+ } else {
446
+ return v8::Local<v8::Value>::New(_env->isolate, _persistent);
447
+ }
448
+ }
449
+
450
+ private:
451
+ static void FinalizeCallback(const v8::WeakCallbackInfo<Reference>& data) {
452
+ Reference* reference = data.GetParameter();
453
+ reference->_persistent.Reset();
454
+
455
+ // Check before calling the finalize callback, because the callback might
456
+ // delete it.
457
+ bool delete_self = reference->_delete_self;
458
+ napi_env env = reference->_env;
459
+
460
+ if (reference->_finalize_callback != nullptr) {
461
+ NAPI_CALL_INTO_MODULE_THROW(env,
462
+ reference->_finalize_callback(
463
+ reference->_env,
464
+ reference->_finalize_data,
465
+ reference->_finalize_hint));
466
+ }
467
+
468
+ if (delete_self) {
469
+ Delete(reference);
470
+ }
471
+ }
472
+
473
+ v8::Persistent<v8::Value> _persistent;
474
+ uint32_t _refcount;
475
+ bool _delete_self;
476
+ };
477
+
478
+ class TryCatch : public v8::TryCatch {
479
+ public:
480
+ explicit TryCatch(napi_env env)
481
+ : v8::TryCatch(env->isolate), _env(env) {}
482
+
483
+ ~TryCatch() {
484
+ if (HasCaught()) {
485
+ _env->last_exception.Reset(_env->isolate, Exception());
486
+ }
487
+ }
488
+
489
+ private:
490
+ napi_env _env;
491
+ };
492
+
493
+ //=== Function napi_callback wrapper =================================
494
+
495
+ // Use this data structure to associate callback data with each N-API function
496
+ // exposed to JavaScript. The structure is stored in a v8::External which gets
497
+ // passed into our callback wrapper. This reduces the performance impact of
498
+ // calling through N-API.
499
+ // Ref: benchmark/misc/function_call
500
+ // Discussion (incl. perf. data): https://github.com/nodejs/node/pull/21072
501
+ struct CallbackBundle {
502
+ // Bind the lifecycle of `this` C++ object to a JavaScript object.
503
+ // We never delete a CallbackBundle C++ object directly.
504
+ void BindLifecycleTo(v8::Isolate* isolate, v8::Local<v8::Value> target) {
505
+ handle.Reset(isolate, target);
506
+ handle.SetWeak(this, WeakCallback, v8::WeakCallbackType::kParameter);
507
+ }
508
+
509
+ napi_env env; // Necessary to invoke C++ NAPI callback
510
+ void* cb_data; // The user provided callback data
511
+ napi_callback function_or_getter;
512
+ napi_callback setter;
513
+ node::Persistent<v8::Value> handle; // Die with this JavaScript object
514
+
515
+ private:
516
+ static void WeakCallback(v8::WeakCallbackInfo<CallbackBundle> const& info) {
517
+ // Use the "WeakCallback mechanism" to delete the C++ `bundle` object.
518
+ // This will be called when the v8::External containing `this` pointer
519
+ // is being GC-ed.
520
+ CallbackBundle* bundle = info.GetParameter();
521
+ if (bundle != nullptr) {
522
+ delete bundle;
523
+ }
524
+ }
525
+ };
526
+
527
+ // Base class extended by classes that wrap V8 function and property callback
528
+ // info.
529
+ class CallbackWrapper {
530
+ public:
531
+ CallbackWrapper(napi_value this_arg, size_t args_length, void* data)
532
+ : _this(this_arg), _args_length(args_length), _data(data) {}
533
+
534
+ virtual napi_value GetNewTarget() = 0;
535
+ virtual void Args(napi_value* buffer, size_t bufferlength) = 0;
536
+ virtual void SetReturnValue(napi_value value) = 0;
537
+
538
+ napi_value This() { return _this; }
539
+
540
+ size_t ArgsLength() { return _args_length; }
541
+
542
+ void* Data() { return _data; }
543
+
544
+ protected:
545
+ const napi_value _this;
546
+ const size_t _args_length;
547
+ void* _data;
548
+ };
549
+
550
+ template <typename Info, napi_callback CallbackBundle::*FunctionField>
551
+ class CallbackWrapperBase : public CallbackWrapper {
552
+ public:
553
+ CallbackWrapperBase(const Info& cbinfo, const size_t args_length)
554
+ : CallbackWrapper(JsValueFromV8LocalValue(cbinfo.This()),
555
+ args_length,
556
+ nullptr),
557
+ _cbinfo(cbinfo) {
558
+ _bundle = reinterpret_cast<CallbackBundle*>(
559
+ v8::Local<v8::External>::Cast(cbinfo.Data())->Value());
560
+ _data = _bundle->cb_data;
561
+ }
562
+
563
+ napi_value GetNewTarget() override { return nullptr; }
564
+
565
+ protected:
566
+ void InvokeCallback() {
567
+ napi_callback_info cbinfo_wrapper = reinterpret_cast<napi_callback_info>(
568
+ static_cast<CallbackWrapper*>(this));
569
+
570
+ // All other pointers we need are stored in `_bundle`
571
+ napi_env env = _bundle->env;
572
+ napi_callback cb = _bundle->*FunctionField;
573
+
574
+ napi_value result;
575
+ NAPI_CALL_INTO_MODULE_THROW(env, result = cb(env, cbinfo_wrapper));
576
+
577
+ if (result != nullptr) {
578
+ this->SetReturnValue(result);
579
+ }
580
+ }
581
+
582
+ const Info& _cbinfo;
583
+ CallbackBundle* _bundle;
584
+ };
585
+
586
+ class FunctionCallbackWrapper
587
+ : public CallbackWrapperBase<v8::FunctionCallbackInfo<v8::Value>,
588
+ &CallbackBundle::function_or_getter> {
589
+ public:
590
+ static void Invoke(const v8::FunctionCallbackInfo<v8::Value>& info) {
591
+ FunctionCallbackWrapper cbwrapper(info);
592
+ cbwrapper.InvokeCallback();
593
+ }
594
+
595
+ explicit FunctionCallbackWrapper(
596
+ const v8::FunctionCallbackInfo<v8::Value>& cbinfo)
597
+ : CallbackWrapperBase(cbinfo, cbinfo.Length()) {}
598
+
599
+ napi_value GetNewTarget() override {
600
+ if (_cbinfo.IsConstructCall()) {
601
+ return v8impl::JsValueFromV8LocalValue(_cbinfo.NewTarget());
602
+ } else {
603
+ return nullptr;
604
+ }
605
+ }
606
+
607
+ /*virtual*/
608
+ void Args(napi_value* buffer, size_t buffer_length) override {
609
+ size_t i = 0;
610
+ size_t min = std::min(buffer_length, _args_length);
611
+
612
+ for (; i < min; i += 1) {
613
+ buffer[i] = v8impl::JsValueFromV8LocalValue(_cbinfo[i]);
614
+ }
615
+
616
+ if (i < buffer_length) {
617
+ napi_value undefined =
618
+ v8impl::JsValueFromV8LocalValue(v8::Undefined(_cbinfo.GetIsolate()));
619
+ for (; i < buffer_length; i += 1) {
620
+ buffer[i] = undefined;
621
+ }
622
+ }
623
+ }
624
+
625
+ /*virtual*/
626
+ void SetReturnValue(napi_value value) override {
627
+ v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
628
+ _cbinfo.GetReturnValue().Set(val);
629
+ }
630
+ };
631
+
632
+ class GetterCallbackWrapper
633
+ : public CallbackWrapperBase<v8::PropertyCallbackInfo<v8::Value>,
634
+ &CallbackBundle::function_or_getter> {
635
+ public:
636
+ static void Invoke(v8::Local<v8::Name> property,
637
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
638
+ GetterCallbackWrapper cbwrapper(info);
639
+ cbwrapper.InvokeCallback();
640
+ }
641
+
642
+ explicit GetterCallbackWrapper(
643
+ const v8::PropertyCallbackInfo<v8::Value>& cbinfo)
644
+ : CallbackWrapperBase(cbinfo, 0) {}
645
+
646
+ /*virtual*/
647
+ void Args(napi_value* buffer, size_t buffer_length) override {
648
+ if (buffer_length > 0) {
649
+ napi_value undefined =
650
+ v8impl::JsValueFromV8LocalValue(v8::Undefined(_cbinfo.GetIsolate()));
651
+ for (size_t i = 0; i < buffer_length; i += 1) {
652
+ buffer[i] = undefined;
653
+ }
654
+ }
655
+ }
656
+
657
+ /*virtual*/
658
+ void SetReturnValue(napi_value value) override {
659
+ v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
660
+ _cbinfo.GetReturnValue().Set(val);
661
+ }
662
+ };
663
+
664
+ class SetterCallbackWrapper
665
+ : public CallbackWrapperBase<v8::PropertyCallbackInfo<void>,
666
+ &CallbackBundle::setter> {
667
+ public:
668
+ static void Invoke(v8::Local<v8::Name> property,
669
+ v8::Local<v8::Value> value,
670
+ const v8::PropertyCallbackInfo<void>& info) {
671
+ SetterCallbackWrapper cbwrapper(info, value);
672
+ cbwrapper.InvokeCallback();
673
+ }
674
+
675
+ SetterCallbackWrapper(const v8::PropertyCallbackInfo<void>& cbinfo,
676
+ const v8::Local<v8::Value>& value)
677
+ : CallbackWrapperBase(cbinfo, 1), _value(value) {}
678
+
679
+ /*virtual*/
680
+ void Args(napi_value* buffer, size_t buffer_length) override {
681
+ if (buffer_length > 0) {
682
+ buffer[0] = v8impl::JsValueFromV8LocalValue(_value);
683
+
684
+ if (buffer_length > 1) {
685
+ napi_value undefined = v8impl::JsValueFromV8LocalValue(
686
+ v8::Undefined(_cbinfo.GetIsolate()));
687
+ for (size_t i = 1; i < buffer_length; i += 1) {
688
+ buffer[i] = undefined;
689
+ }
690
+ }
691
+ }
692
+ }
693
+
694
+ /*virtual*/
695
+ void SetReturnValue(napi_value value) override {
696
+ // Ignore any value returned from a setter callback.
697
+ }
698
+
699
+ private:
700
+ const v8::Local<v8::Value>& _value;
701
+ };
702
+
703
+ // Creates an object to be made available to the static function callback
704
+ // wrapper, used to retrieve the native callback function and data pointer.
705
+ static
706
+ v8::Local<v8::Value> CreateFunctionCallbackData(napi_env env,
707
+ napi_callback cb,
708
+ void* data) {
709
+ CallbackBundle* bundle = new CallbackBundle();
710
+ bundle->function_or_getter = cb;
711
+ bundle->cb_data = data;
712
+ bundle->env = env;
713
+ v8::Local<v8::Value> cbdata = v8::External::New(env->isolate, bundle);
714
+ bundle->BindLifecycleTo(env->isolate, cbdata);
715
+
716
+ return cbdata;
717
+ }
718
+
719
+ // Creates an object to be made available to the static getter/setter
720
+ // callback wrapper, used to retrieve the native getter/setter callback
721
+ // function and data pointer.
722
+ static
723
+ v8::Local<v8::Value> CreateAccessorCallbackData(napi_env env,
724
+ napi_callback getter,
725
+ napi_callback setter,
726
+ void* data) {
727
+ CallbackBundle* bundle = new CallbackBundle();
728
+ bundle->function_or_getter = getter;
729
+ bundle->setter = setter;
730
+ bundle->cb_data = data;
731
+ bundle->env = env;
732
+ v8::Local<v8::Value> cbdata = v8::External::New(env->isolate, bundle);
733
+ bundle->BindLifecycleTo(env->isolate, cbdata);
734
+
735
+ return cbdata;
736
+ }
737
+
738
+ int kWrapperFields = 3;
739
+
740
+ // Pointer used to identify items wrapped by N-API. Used by FindWrapper and
741
+ // napi_wrap().
742
+ const char napi_wrap_name[] = "N-API Wrapper";
743
+
744
+ // Search the object's prototype chain for the wrapper object. Usually the
745
+ // wrapper would be the first in the chain, but it is OK for other objects to
746
+ // be inserted in the prototype chain.
747
+ static
748
+ bool FindWrapper(v8::Local<v8::Object> obj,
749
+ v8::Local<v8::Object>* result = nullptr,
750
+ v8::Local<v8::Object>* parent = nullptr) {
751
+ v8::Local<v8::Object> wrapper = obj;
752
+
753
+ do {
754
+ v8::Local<v8::Value> proto = wrapper->GetPrototype();
755
+ if (proto.IsEmpty() || !proto->IsObject()) {
756
+ return false;
757
+ }
758
+ if (parent != nullptr) {
759
+ *parent = wrapper;
760
+ }
761
+ wrapper = proto.As<v8::Object>();
762
+ if (wrapper->InternalFieldCount() == kWrapperFields) {
763
+ v8::Local<v8::Value> external = wrapper->GetInternalField(1);
764
+ if (external->IsExternal() &&
765
+ external.As<v8::External>()->Value() == v8impl::napi_wrap_name) {
766
+ break;
767
+ }
768
+ }
769
+ } while (true);
770
+
771
+ if (result != nullptr) {
772
+ *result = wrapper;
773
+ }
774
+ return true;
775
+ }
776
+
777
+ static void DeleteEnv(napi_env env, void* data, void* hint) {
778
+ delete env;
779
+ }
780
+
781
+ static
782
+ napi_env GetEnv(v8::Local<v8::Context> context) {
783
+ napi_env result;
784
+
785
+ auto isolate = context->GetIsolate();
786
+ auto global = context->Global();
787
+
788
+ // In the case of the string for which we grab the private and the value of
789
+ // the private on the global object we can call .ToLocalChecked() directly
790
+ // because we need to stop hard if either of them is empty.
791
+ //
792
+ // Re https://github.com/nodejs/node/pull/14217#discussion_r128775149
793
+ auto key = v8::Private::ForApi(isolate,
794
+ v8::String::NewFromOneByte(isolate,
795
+ reinterpret_cast<const uint8_t*>("N-API Environment"),
796
+ v8::NewStringType::kInternalized).ToLocalChecked());
797
+ auto value = global->GetPrivate(context, key).ToLocalChecked();
798
+
799
+ if (value->IsExternal()) {
800
+ result = static_cast<napi_env>(value.As<v8::External>()->Value());
801
+ } else {
802
+ result = new napi_env__(isolate);
803
+ auto external = v8::External::New(isolate, result);
804
+
805
+ // We must also stop hard if the result of assigning the env to the global
806
+ // is either nothing or false.
807
+ CHECK(global->SetPrivate(context, key, external).FromJust());
808
+
809
+ // Create a self-destructing reference to external that will get rid of the
810
+ // napi_env when external goes out of scope.
811
+ Reference::New(result, external, 0, true, DeleteEnv, nullptr, nullptr);
812
+ }
813
+
814
+ return result;
815
+ }
816
+
817
+ static
818
+ napi_status Unwrap(napi_env env,
819
+ napi_value js_object,
820
+ void** result,
821
+ v8::Local<v8::Object>* wrapper,
822
+ v8::Local<v8::Object>* parent = nullptr) {
823
+ CHECK_ARG(env, js_object);
824
+ CHECK_ARG(env, result);
825
+
826
+ v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(js_object);
827
+ RETURN_STATUS_IF_FALSE(env, value->IsObject(), napi_invalid_arg);
828
+ v8::Local<v8::Object> obj = value.As<v8::Object>();
829
+
830
+ RETURN_STATUS_IF_FALSE(
831
+ env, v8impl::FindWrapper(obj, wrapper, parent), napi_invalid_arg);
832
+
833
+ v8::Local<v8::Value> unwrappedValue = (*wrapper)->GetInternalField(0);
834
+ RETURN_STATUS_IF_FALSE(env, unwrappedValue->IsExternal(), napi_invalid_arg);
835
+
836
+ *result = unwrappedValue.As<v8::External>()->Value();
837
+
838
+ return napi_ok;
839
+ }
840
+
841
+ static
842
+ napi_status ConcludeDeferred(napi_env env,
843
+ napi_deferred deferred,
844
+ napi_value result,
845
+ bool is_resolved) {
846
+ NAPI_PREAMBLE(env);
847
+ CHECK_ARG(env, result);
848
+
849
+ v8::Local<v8::Context> context = env->isolate->GetCurrentContext();
850
+ v8::Persistent<v8::Value>* deferred_ref =
851
+ V8PersistentFromJsDeferred(deferred);
852
+ v8::Local<v8::Value> v8_deferred =
853
+ v8::Local<v8::Value>::New(env->isolate, *deferred_ref);
854
+
855
+ auto v8_resolver = v8::Local<v8::Promise::Resolver>::Cast(v8_deferred);
856
+
857
+ v8::Maybe<bool> success = is_resolved ?
858
+ v8_resolver->Resolve(context, v8impl::V8LocalValueFromJsValue(result)) :
859
+ v8_resolver->Reject(context, v8impl::V8LocalValueFromJsValue(result));
860
+
861
+ deferred_ref->Reset();
862
+ delete deferred_ref;
863
+
864
+ RETURN_STATUS_IF_FALSE(env, success.FromMaybe(false), napi_generic_failure);
865
+
866
+ return GET_RETURN_STATUS(env);
867
+ }
868
+
869
+ } // end of namespace v8impl
870
+
871
+ // Intercepts the Node-V8 module registration callback. Converts parameters
872
+ // to NAPI equivalents and then calls the registration callback specified
873
+ // by the NAPI module.
874
+ void napi_module_register_cb(v8::Local<v8::Object> exports,
875
+ v8::Local<v8::Value> module,
876
+ v8::Local<v8::Context> context,
877
+ void* priv) {
878
+ napi_module* mod = static_cast<napi_module*>(priv);
879
+
880
+ // Create a new napi_env for this module or reference one if a pre-existing
881
+ // one is found.
882
+ napi_env env = v8impl::GetEnv(context);
883
+
884
+ napi_value _exports;
885
+ NAPI_CALL_INTO_MODULE_THROW(env,
886
+ _exports = mod->nm_register_func(env,
887
+ v8impl::JsValueFromV8LocalValue(exports)));
888
+
889
+ // If register function returned a non-null exports object different from
890
+ // the exports object we passed it, set that as the "exports" property of
891
+ // the module.
892
+ if (_exports != nullptr &&
893
+ _exports != v8impl::JsValueFromV8LocalValue(exports)) {
894
+ napi_value _module = v8impl::JsValueFromV8LocalValue(module);
895
+ napi_set_named_property(env, _module, "exports", _exports);
896
+ }
897
+ }
898
+
899
+ } // end of anonymous namespace
900
+
901
+ // Registers a NAPI module.
902
+ void napi_module_register(napi_module* mod) {
903
+ node::node_module* nm = new node::node_module {
904
+ NODE_MODULE_VERSION,
905
+ mod->nm_flags,
906
+ nullptr,
907
+ mod->nm_filename,
908
+ nullptr,
909
+ napi_module_register_cb,
910
+ mod->nm_modname,
911
+ mod, // priv
912
+ nullptr,
913
+ };
914
+ node::node_module_register(nm);
915
+ }
916
+
917
+ // Warning: Keep in-sync with napi_status enum
918
+ static
919
+ const char* error_messages[] = {nullptr,
920
+ "Invalid argument",
921
+ "An object was expected",
922
+ "A string was expected",
923
+ "A string or symbol was expected",
924
+ "A function was expected",
925
+ "A number was expected",
926
+ "A boolean was expected",
927
+ "An array was expected",
928
+ "Unknown failure",
929
+ "An exception is pending",
930
+ "The async work item was cancelled",
931
+ "napi_escape_handle already called on scope"};
932
+
933
+ static inline napi_status napi_clear_last_error(napi_env env) {
934
+ env->last_error.error_code = napi_ok;
935
+
936
+ // TODO(boingoing): Should this be a callback?
937
+ env->last_error.engine_error_code = 0;
938
+ env->last_error.engine_reserved = nullptr;
939
+ return napi_ok;
940
+ }
941
+
942
+ static inline
943
+ napi_status napi_set_last_error(napi_env env, napi_status error_code,
944
+ uint32_t engine_error_code,
945
+ void* engine_reserved) {
946
+ env->last_error.error_code = error_code;
947
+ env->last_error.engine_error_code = engine_error_code;
948
+ env->last_error.engine_reserved = engine_reserved;
949
+ return error_code;
950
+ }
951
+
952
+ napi_status napi_get_last_error_info(napi_env env,
953
+ const napi_extended_error_info** result) {
954
+ CHECK_ENV(env);
955
+ CHECK_ARG(env, result);
956
+
957
+ // you must update this assert to reference the last message
958
+ // in the napi_status enum each time a new error message is added.
959
+ // We don't have a napi_status_last as this would result in an ABI
960
+ // change each time a message was added.
961
+ static_assert(
962
+ node::arraysize(error_messages) == napi_escape_called_twice + 1,
963
+ "Count of error messages must match count of error values");
964
+ CHECK_LE(env->last_error.error_code, napi_escape_called_twice);
965
+
966
+ // Wait until someone requests the last error information to fetch the error
967
+ // message string
968
+ env->last_error.error_message =
969
+ error_messages[env->last_error.error_code];
970
+
971
+ *result = &(env->last_error);
972
+ return napi_ok;
973
+ }
974
+
975
+ napi_status napi_fatal_exception(napi_env env, napi_value err) {
976
+ NAPI_PREAMBLE(env);
977
+ CHECK_ARG(env, err);
978
+
979
+ v8::Local<v8::Value> local_err = v8impl::V8LocalValueFromJsValue(err);
980
+ v8impl::trigger_fatal_exception(env, local_err);
981
+
982
+ return napi_clear_last_error(env);
983
+ }
984
+
985
+ NAPI_NO_RETURN void napi_fatal_error(const char* location,
986
+ size_t location_len,
987
+ const char* message,
988
+ size_t message_len) {
989
+ std::string location_string;
990
+ std::string message_string;
991
+
992
+ if (location_len != NAPI_AUTO_LENGTH) {
993
+ location_string.assign(
994
+ const_cast<char*>(location), location_len);
995
+ } else {
996
+ location_string.assign(
997
+ const_cast<char*>(location), strlen(location));
998
+ }
999
+
1000
+ if (message_len != NAPI_AUTO_LENGTH) {
1001
+ message_string.assign(
1002
+ const_cast<char*>(message), message_len);
1003
+ } else {
1004
+ message_string.assign(
1005
+ const_cast<char*>(message), strlen(message));
1006
+ }
1007
+
1008
+ node::FatalError(location_string.c_str(), message_string.c_str());
1009
+ }
1010
+
1011
+ napi_status napi_create_function(napi_env env,
1012
+ const char* utf8name,
1013
+ size_t length,
1014
+ napi_callback cb,
1015
+ void* callback_data,
1016
+ napi_value* result) {
1017
+ NAPI_PREAMBLE(env);
1018
+ CHECK_ARG(env, result);
1019
+ CHECK_ARG(env, cb);
1020
+
1021
+ v8::Isolate* isolate = env->isolate;
1022
+ v8::Local<v8::Function> return_value;
1023
+ v8::EscapableHandleScope scope(isolate);
1024
+ v8::Local<v8::Value> cbdata =
1025
+ v8impl::CreateFunctionCallbackData(env, cb, callback_data);
1026
+
1027
+ RETURN_STATUS_IF_FALSE(env, !cbdata.IsEmpty(), napi_generic_failure);
1028
+
1029
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
1030
+ v8::MaybeLocal<v8::Function> maybe_function =
1031
+ v8::Function::New(context,
1032
+ v8impl::FunctionCallbackWrapper::Invoke,
1033
+ cbdata);
1034
+ CHECK_MAYBE_EMPTY(env, maybe_function, napi_generic_failure);
1035
+
1036
+ return_value = scope.Escape(maybe_function.ToLocalChecked());
1037
+
1038
+ if (utf8name != nullptr) {
1039
+ v8::Local<v8::String> name_string;
1040
+ CHECK_NEW_FROM_UTF8_LEN(env, name_string, utf8name, length);
1041
+ return_value->SetName(name_string);
1042
+ }
1043
+
1044
+ *result = v8impl::JsValueFromV8LocalValue(return_value);
1045
+
1046
+ return GET_RETURN_STATUS(env);
1047
+ }
1048
+
1049
+ napi_status napi_define_class(napi_env env,
1050
+ const char* utf8name,
1051
+ size_t length,
1052
+ napi_callback constructor,
1053
+ void* callback_data,
1054
+ size_t property_count,
1055
+ const napi_property_descriptor* properties,
1056
+ napi_value* result) {
1057
+ NAPI_PREAMBLE(env);
1058
+ CHECK_ARG(env, result);
1059
+ CHECK_ARG(env, constructor);
1060
+
1061
+ v8::Isolate* isolate = env->isolate;
1062
+
1063
+ v8::EscapableHandleScope scope(isolate);
1064
+ v8::Local<v8::Value> cbdata =
1065
+ v8impl::CreateFunctionCallbackData(env, constructor, callback_data);
1066
+
1067
+ RETURN_STATUS_IF_FALSE(env, !cbdata.IsEmpty(), napi_generic_failure);
1068
+
1069
+ v8::Local<v8::FunctionTemplate> tpl = v8::FunctionTemplate::New(
1070
+ isolate, v8impl::FunctionCallbackWrapper::Invoke, cbdata);
1071
+
1072
+ v8::Local<v8::String> name_string;
1073
+ CHECK_NEW_FROM_UTF8_LEN(env, name_string, utf8name, length);
1074
+ tpl->SetClassName(name_string);
1075
+
1076
+ size_t static_property_count = 0;
1077
+ for (size_t i = 0; i < property_count; i++) {
1078
+ const napi_property_descriptor* p = properties + i;
1079
+
1080
+ if ((p->attributes & napi_static) != 0) {
1081
+ // Static properties are handled separately below.
1082
+ static_property_count++;
1083
+ continue;
1084
+ }
1085
+
1086
+ v8::Local<v8::Name> property_name;
1087
+ napi_status status =
1088
+ v8impl::V8NameFromPropertyDescriptor(env, p, &property_name);
1089
+
1090
+ if (status != napi_ok) {
1091
+ return napi_set_last_error(env, status);
1092
+ }
1093
+
1094
+ v8::PropertyAttribute attributes =
1095
+ v8impl::V8PropertyAttributesFromDescriptor(p);
1096
+
1097
+ // This code is similar to that in napi_define_properties(); the
1098
+ // difference is it applies to a template instead of an object.
1099
+ if (p->getter != nullptr || p->setter != nullptr) {
1100
+ v8::Local<v8::Value> cbdata = v8impl::CreateAccessorCallbackData(
1101
+ env, p->getter, p->setter, p->data);
1102
+
1103
+ tpl->PrototypeTemplate()->SetAccessor(
1104
+ property_name,
1105
+ p->getter ? v8impl::GetterCallbackWrapper::Invoke : nullptr,
1106
+ p->setter ? v8impl::SetterCallbackWrapper::Invoke : nullptr,
1107
+ cbdata,
1108
+ v8::AccessControl::DEFAULT,
1109
+ attributes);
1110
+ } else if (p->method != nullptr) {
1111
+ v8::Local<v8::Value> cbdata =
1112
+ v8impl::CreateFunctionCallbackData(env, p->method, p->data);
1113
+
1114
+ RETURN_STATUS_IF_FALSE(env, !cbdata.IsEmpty(), napi_generic_failure);
1115
+
1116
+ v8::Local<v8::FunctionTemplate> t =
1117
+ v8::FunctionTemplate::New(isolate,
1118
+ v8impl::FunctionCallbackWrapper::Invoke,
1119
+ cbdata,
1120
+ v8::Signature::New(isolate, tpl));
1121
+
1122
+ tpl->PrototypeTemplate()->Set(property_name, t, attributes);
1123
+ } else {
1124
+ v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(p->value);
1125
+ tpl->PrototypeTemplate()->Set(property_name, value, attributes);
1126
+ }
1127
+ }
1128
+
1129
+ *result = v8impl::JsValueFromV8LocalValue(scope.Escape(tpl->GetFunction()));
1130
+
1131
+ if (static_property_count > 0) {
1132
+ std::vector<napi_property_descriptor> static_descriptors;
1133
+ static_descriptors.reserve(static_property_count);
1134
+
1135
+ for (size_t i = 0; i < property_count; i++) {
1136
+ const napi_property_descriptor* p = properties + i;
1137
+ if ((p->attributes & napi_static) != 0) {
1138
+ static_descriptors.push_back(*p);
1139
+ }
1140
+ }
1141
+
1142
+ napi_status status =
1143
+ napi_define_properties(env,
1144
+ *result,
1145
+ static_descriptors.size(),
1146
+ static_descriptors.data());
1147
+ if (status != napi_ok) return status;
1148
+ }
1149
+
1150
+ return GET_RETURN_STATUS(env);
1151
+ }
1152
+
1153
+ napi_status napi_get_property_names(napi_env env,
1154
+ napi_value object,
1155
+ napi_value* result) {
1156
+ NAPI_PREAMBLE(env);
1157
+ CHECK_ARG(env, result);
1158
+
1159
+ v8::Isolate* isolate = env->isolate;
1160
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
1161
+ v8::Local<v8::Object> obj;
1162
+ CHECK_TO_OBJECT(env, context, obj, object);
1163
+
1164
+ auto maybe_propertynames = obj->GetPropertyNames(context);
1165
+
1166
+ CHECK_MAYBE_EMPTY(env, maybe_propertynames, napi_generic_failure);
1167
+
1168
+ *result = v8impl::JsValueFromV8LocalValue(
1169
+ maybe_propertynames.ToLocalChecked());
1170
+ return GET_RETURN_STATUS(env);
1171
+ }
1172
+
1173
+ napi_status napi_set_property(napi_env env,
1174
+ napi_value object,
1175
+ napi_value key,
1176
+ napi_value value) {
1177
+ NAPI_PREAMBLE(env);
1178
+ CHECK_ARG(env, key);
1179
+ CHECK_ARG(env, value);
1180
+
1181
+ v8::Isolate* isolate = env->isolate;
1182
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
1183
+ v8::Local<v8::Object> obj;
1184
+
1185
+ CHECK_TO_OBJECT(env, context, obj, object);
1186
+
1187
+ v8::Local<v8::Value> k = v8impl::V8LocalValueFromJsValue(key);
1188
+ v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
1189
+
1190
+ v8::Maybe<bool> set_maybe = obj->Set(context, k, val);
1191
+
1192
+ RETURN_STATUS_IF_FALSE(env, set_maybe.FromMaybe(false), napi_generic_failure);
1193
+ return GET_RETURN_STATUS(env);
1194
+ }
1195
+
1196
+ napi_status napi_has_property(napi_env env,
1197
+ napi_value object,
1198
+ napi_value key,
1199
+ bool* result) {
1200
+ NAPI_PREAMBLE(env);
1201
+ CHECK_ARG(env, result);
1202
+ CHECK_ARG(env, key);
1203
+
1204
+ v8::Isolate* isolate = env->isolate;
1205
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
1206
+ v8::Local<v8::Object> obj;
1207
+
1208
+ CHECK_TO_OBJECT(env, context, obj, object);
1209
+
1210
+ v8::Local<v8::Value> k = v8impl::V8LocalValueFromJsValue(key);
1211
+ v8::Maybe<bool> has_maybe = obj->Has(context, k);
1212
+
1213
+ CHECK_MAYBE_NOTHING(env, has_maybe, napi_generic_failure);
1214
+
1215
+ *result = has_maybe.FromMaybe(false);
1216
+ return GET_RETURN_STATUS(env);
1217
+ }
1218
+
1219
+ napi_status napi_get_property(napi_env env,
1220
+ napi_value object,
1221
+ napi_value key,
1222
+ napi_value* result) {
1223
+ NAPI_PREAMBLE(env);
1224
+ CHECK_ARG(env, key);
1225
+ CHECK_ARG(env, result);
1226
+
1227
+ v8::Isolate* isolate = env->isolate;
1228
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
1229
+ v8::Local<v8::Value> k = v8impl::V8LocalValueFromJsValue(key);
1230
+ v8::Local<v8::Object> obj;
1231
+
1232
+ CHECK_TO_OBJECT(env, context, obj, object);
1233
+
1234
+ auto get_maybe = obj->Get(context, k);
1235
+
1236
+ CHECK_MAYBE_EMPTY(env, get_maybe, napi_generic_failure);
1237
+
1238
+ v8::Local<v8::Value> val = get_maybe.ToLocalChecked();
1239
+ *result = v8impl::JsValueFromV8LocalValue(val);
1240
+ return GET_RETURN_STATUS(env);
1241
+ }
1242
+
1243
+ napi_status napi_delete_property(napi_env env,
1244
+ napi_value object,
1245
+ napi_value key,
1246
+ bool* result) {
1247
+ NAPI_PREAMBLE(env);
1248
+ CHECK_ARG(env, key);
1249
+
1250
+ v8::Isolate* isolate = env->isolate;
1251
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
1252
+ v8::Local<v8::Value> k = v8impl::V8LocalValueFromJsValue(key);
1253
+ v8::Local<v8::Object> obj;
1254
+
1255
+ CHECK_TO_OBJECT(env, context, obj, object);
1256
+ v8::Maybe<bool> delete_maybe = obj->Delete(context, k);
1257
+ CHECK_MAYBE_NOTHING(env, delete_maybe, napi_generic_failure);
1258
+
1259
+ if (result != NULL)
1260
+ *result = delete_maybe.FromMaybe(false);
1261
+
1262
+ return GET_RETURN_STATUS(env);
1263
+ }
1264
+
1265
+ napi_status napi_has_own_property(napi_env env,
1266
+ napi_value object,
1267
+ napi_value key,
1268
+ bool* result) {
1269
+ NAPI_PREAMBLE(env);
1270
+ CHECK_ARG(env, key);
1271
+
1272
+ v8::Isolate* isolate = env->isolate;
1273
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
1274
+ v8::Local<v8::Object> obj;
1275
+
1276
+ CHECK_TO_OBJECT(env, context, obj, object);
1277
+ v8::Local<v8::Value> k = v8impl::V8LocalValueFromJsValue(key);
1278
+ RETURN_STATUS_IF_FALSE(env, k->IsName(), napi_name_expected);
1279
+ v8::Maybe<bool> has_maybe = obj->HasOwnProperty(context, k.As<v8::Name>());
1280
+ CHECK_MAYBE_NOTHING(env, has_maybe, napi_generic_failure);
1281
+ *result = has_maybe.FromMaybe(false);
1282
+
1283
+ return GET_RETURN_STATUS(env);
1284
+ }
1285
+
1286
+ napi_status napi_set_named_property(napi_env env,
1287
+ napi_value object,
1288
+ const char* utf8name,
1289
+ napi_value value) {
1290
+ NAPI_PREAMBLE(env);
1291
+ CHECK_ARG(env, value);
1292
+
1293
+ v8::Isolate* isolate = env->isolate;
1294
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
1295
+ v8::Local<v8::Object> obj;
1296
+
1297
+ CHECK_TO_OBJECT(env, context, obj, object);
1298
+
1299
+ v8::Local<v8::Name> key;
1300
+ CHECK_NEW_FROM_UTF8(env, key, utf8name);
1301
+
1302
+ v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
1303
+
1304
+ v8::Maybe<bool> set_maybe = obj->Set(context, key, val);
1305
+
1306
+ RETURN_STATUS_IF_FALSE(env, set_maybe.FromMaybe(false), napi_generic_failure);
1307
+ return GET_RETURN_STATUS(env);
1308
+ }
1309
+
1310
+ napi_status napi_has_named_property(napi_env env,
1311
+ napi_value object,
1312
+ const char* utf8name,
1313
+ bool* result) {
1314
+ NAPI_PREAMBLE(env);
1315
+ CHECK_ARG(env, result);
1316
+
1317
+ v8::Isolate* isolate = env->isolate;
1318
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
1319
+ v8::Local<v8::Object> obj;
1320
+
1321
+ CHECK_TO_OBJECT(env, context, obj, object);
1322
+
1323
+ v8::Local<v8::Name> key;
1324
+ CHECK_NEW_FROM_UTF8(env, key, utf8name);
1325
+
1326
+ v8::Maybe<bool> has_maybe = obj->Has(context, key);
1327
+
1328
+ CHECK_MAYBE_NOTHING(env, has_maybe, napi_generic_failure);
1329
+
1330
+ *result = has_maybe.FromMaybe(false);
1331
+ return GET_RETURN_STATUS(env);
1332
+ }
1333
+
1334
+ napi_status napi_get_named_property(napi_env env,
1335
+ napi_value object,
1336
+ const char* utf8name,
1337
+ napi_value* result) {
1338
+ NAPI_PREAMBLE(env);
1339
+ CHECK_ARG(env, result);
1340
+
1341
+ v8::Isolate* isolate = env->isolate;
1342
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
1343
+
1344
+ v8::Local<v8::Name> key;
1345
+ CHECK_NEW_FROM_UTF8(env, key, utf8name);
1346
+
1347
+ v8::Local<v8::Object> obj;
1348
+
1349
+ CHECK_TO_OBJECT(env, context, obj, object);
1350
+
1351
+ auto get_maybe = obj->Get(context, key);
1352
+
1353
+ CHECK_MAYBE_EMPTY(env, get_maybe, napi_generic_failure);
1354
+
1355
+ v8::Local<v8::Value> val = get_maybe.ToLocalChecked();
1356
+ *result = v8impl::JsValueFromV8LocalValue(val);
1357
+ return GET_RETURN_STATUS(env);
1358
+ }
1359
+
1360
+ napi_status napi_set_element(napi_env env,
1361
+ napi_value object,
1362
+ uint32_t index,
1363
+ napi_value value) {
1364
+ NAPI_PREAMBLE(env);
1365
+ CHECK_ARG(env, value);
1366
+
1367
+ v8::Isolate* isolate = env->isolate;
1368
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
1369
+ v8::Local<v8::Object> obj;
1370
+
1371
+ CHECK_TO_OBJECT(env, context, obj, object);
1372
+
1373
+ v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
1374
+ auto set_maybe = obj->Set(context, index, val);
1375
+
1376
+ RETURN_STATUS_IF_FALSE(env, set_maybe.FromMaybe(false), napi_generic_failure);
1377
+
1378
+ return GET_RETURN_STATUS(env);
1379
+ }
1380
+
1381
+ napi_status napi_has_element(napi_env env,
1382
+ napi_value object,
1383
+ uint32_t index,
1384
+ bool* result) {
1385
+ NAPI_PREAMBLE(env);
1386
+ CHECK_ARG(env, result);
1387
+
1388
+ v8::Isolate* isolate = env->isolate;
1389
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
1390
+ v8::Local<v8::Object> obj;
1391
+
1392
+ CHECK_TO_OBJECT(env, context, obj, object);
1393
+
1394
+ v8::Maybe<bool> has_maybe = obj->Has(context, index);
1395
+
1396
+ CHECK_MAYBE_NOTHING(env, has_maybe, napi_generic_failure);
1397
+
1398
+ *result = has_maybe.FromMaybe(false);
1399
+ return GET_RETURN_STATUS(env);
1400
+ }
1401
+
1402
+ napi_status napi_get_element(napi_env env,
1403
+ napi_value object,
1404
+ uint32_t index,
1405
+ napi_value* result) {
1406
+ NAPI_PREAMBLE(env);
1407
+ CHECK_ARG(env, result);
1408
+
1409
+ v8::Isolate* isolate = env->isolate;
1410
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
1411
+ v8::Local<v8::Object> obj;
1412
+
1413
+ CHECK_TO_OBJECT(env, context, obj, object);
1414
+
1415
+ auto get_maybe = obj->Get(context, index);
1416
+
1417
+ CHECK_MAYBE_EMPTY(env, get_maybe, napi_generic_failure);
1418
+
1419
+ *result = v8impl::JsValueFromV8LocalValue(get_maybe.ToLocalChecked());
1420
+ return GET_RETURN_STATUS(env);
1421
+ }
1422
+
1423
+ napi_status napi_delete_element(napi_env env,
1424
+ napi_value object,
1425
+ uint32_t index,
1426
+ bool* result) {
1427
+ NAPI_PREAMBLE(env);
1428
+
1429
+ v8::Isolate* isolate = env->isolate;
1430
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
1431
+ v8::Local<v8::Object> obj;
1432
+
1433
+ CHECK_TO_OBJECT(env, context, obj, object);
1434
+ v8::Maybe<bool> delete_maybe = obj->Delete(context, index);
1435
+ CHECK_MAYBE_NOTHING(env, delete_maybe, napi_generic_failure);
1436
+
1437
+ if (result != NULL)
1438
+ *result = delete_maybe.FromMaybe(false);
1439
+
1440
+ return GET_RETURN_STATUS(env);
1441
+ }
1442
+
1443
+ napi_status napi_define_properties(napi_env env,
1444
+ napi_value object,
1445
+ size_t property_count,
1446
+ const napi_property_descriptor* properties) {
1447
+ NAPI_PREAMBLE(env);
1448
+ if (property_count > 0) {
1449
+ CHECK_ARG(env, properties);
1450
+ }
1451
+
1452
+ v8::Isolate* isolate = env->isolate;
1453
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
1454
+
1455
+ v8::Local<v8::Object> obj;
1456
+ CHECK_TO_OBJECT(env, context, obj, object);
1457
+
1458
+ for (size_t i = 0; i < property_count; i++) {
1459
+ const napi_property_descriptor* p = &properties[i];
1460
+
1461
+ v8::Local<v8::Name> property_name;
1462
+ napi_status status =
1463
+ v8impl::V8NameFromPropertyDescriptor(env, p, &property_name);
1464
+
1465
+ if (status != napi_ok) {
1466
+ return napi_set_last_error(env, status);
1467
+ }
1468
+
1469
+ v8::PropertyAttribute attributes =
1470
+ v8impl::V8PropertyAttributesFromDescriptor(p);
1471
+
1472
+ if (p->getter != nullptr || p->setter != nullptr) {
1473
+ v8::Local<v8::Value> cbdata = v8impl::CreateAccessorCallbackData(
1474
+ env,
1475
+ p->getter,
1476
+ p->setter,
1477
+ p->data);
1478
+
1479
+ auto set_maybe = obj->SetAccessor(
1480
+ context,
1481
+ property_name,
1482
+ p->getter ? v8impl::GetterCallbackWrapper::Invoke : nullptr,
1483
+ p->setter ? v8impl::SetterCallbackWrapper::Invoke : nullptr,
1484
+ cbdata,
1485
+ v8::AccessControl::DEFAULT,
1486
+ attributes);
1487
+
1488
+ if (!set_maybe.FromMaybe(false)) {
1489
+ return napi_set_last_error(env, napi_invalid_arg);
1490
+ }
1491
+ } else if (p->method != nullptr) {
1492
+ v8::Local<v8::Value> cbdata =
1493
+ v8impl::CreateFunctionCallbackData(env, p->method, p->data);
1494
+
1495
+ CHECK_MAYBE_EMPTY(env, cbdata, napi_generic_failure);
1496
+
1497
+ v8::MaybeLocal<v8::Function> maybe_fn =
1498
+ v8::Function::New(context,
1499
+ v8impl::FunctionCallbackWrapper::Invoke,
1500
+ cbdata);
1501
+
1502
+ CHECK_MAYBE_EMPTY(env, maybe_fn, napi_generic_failure);
1503
+
1504
+ auto define_maybe = obj->DefineOwnProperty(
1505
+ context, property_name, maybe_fn.ToLocalChecked(), attributes);
1506
+
1507
+ if (!define_maybe.FromMaybe(false)) {
1508
+ return napi_set_last_error(env, napi_generic_failure);
1509
+ }
1510
+ } else {
1511
+ v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(p->value);
1512
+
1513
+ auto define_maybe =
1514
+ obj->DefineOwnProperty(context, property_name, value, attributes);
1515
+
1516
+ if (!define_maybe.FromMaybe(false)) {
1517
+ return napi_set_last_error(env, napi_invalid_arg);
1518
+ }
1519
+ }
1520
+ }
1521
+
1522
+ return GET_RETURN_STATUS(env);
1523
+ }
1524
+
1525
+ napi_status napi_is_array(napi_env env, napi_value value, bool* result) {
1526
+ CHECK_ENV(env);
1527
+ CHECK_ARG(env, value);
1528
+ CHECK_ARG(env, result);
1529
+
1530
+ v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
1531
+
1532
+ *result = val->IsArray();
1533
+ return napi_clear_last_error(env);
1534
+ }
1535
+
1536
+ napi_status napi_get_array_length(napi_env env,
1537
+ napi_value value,
1538
+ uint32_t* result) {
1539
+ NAPI_PREAMBLE(env);
1540
+ CHECK_ARG(env, value);
1541
+ CHECK_ARG(env, result);
1542
+
1543
+ v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
1544
+ RETURN_STATUS_IF_FALSE(env, val->IsArray(), napi_array_expected);
1545
+
1546
+ v8::Local<v8::Array> arr = val.As<v8::Array>();
1547
+ *result = arr->Length();
1548
+
1549
+ return GET_RETURN_STATUS(env);
1550
+ }
1551
+
1552
+ napi_status napi_strict_equals(napi_env env,
1553
+ napi_value lhs,
1554
+ napi_value rhs,
1555
+ bool* result) {
1556
+ NAPI_PREAMBLE(env);
1557
+ CHECK_ARG(env, lhs);
1558
+ CHECK_ARG(env, rhs);
1559
+ CHECK_ARG(env, result);
1560
+
1561
+ v8::Local<v8::Value> a = v8impl::V8LocalValueFromJsValue(lhs);
1562
+ v8::Local<v8::Value> b = v8impl::V8LocalValueFromJsValue(rhs);
1563
+
1564
+ *result = a->StrictEquals(b);
1565
+ return GET_RETURN_STATUS(env);
1566
+ }
1567
+
1568
+ napi_status napi_get_prototype(napi_env env,
1569
+ napi_value object,
1570
+ napi_value* result) {
1571
+ NAPI_PREAMBLE(env);
1572
+ CHECK_ARG(env, result);
1573
+
1574
+ v8::Isolate* isolate = env->isolate;
1575
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
1576
+
1577
+ v8::Local<v8::Object> obj;
1578
+ CHECK_TO_OBJECT(env, context, obj, object);
1579
+
1580
+ v8::Local<v8::Value> val = obj->GetPrototype();
1581
+ *result = v8impl::JsValueFromV8LocalValue(val);
1582
+ return GET_RETURN_STATUS(env);
1583
+ }
1584
+
1585
+ napi_status napi_create_object(napi_env env, napi_value* result) {
1586
+ CHECK_ENV(env);
1587
+ CHECK_ARG(env, result);
1588
+
1589
+ *result = v8impl::JsValueFromV8LocalValue(
1590
+ v8::Object::New(env->isolate));
1591
+
1592
+ return napi_clear_last_error(env);
1593
+ }
1594
+
1595
+ napi_status napi_create_array(napi_env env, napi_value* result) {
1596
+ CHECK_ENV(env);
1597
+ CHECK_ARG(env, result);
1598
+
1599
+ *result = v8impl::JsValueFromV8LocalValue(
1600
+ v8::Array::New(env->isolate));
1601
+
1602
+ return napi_clear_last_error(env);
1603
+ }
1604
+
1605
+ napi_status napi_create_array_with_length(napi_env env,
1606
+ size_t length,
1607
+ napi_value* result) {
1608
+ CHECK_ENV(env);
1609
+ CHECK_ARG(env, result);
1610
+
1611
+ *result = v8impl::JsValueFromV8LocalValue(
1612
+ v8::Array::New(env->isolate, length));
1613
+
1614
+ return napi_clear_last_error(env);
1615
+ }
1616
+
1617
+ napi_status napi_create_string_latin1(napi_env env,
1618
+ const char* str,
1619
+ size_t length,
1620
+ napi_value* result) {
1621
+ CHECK_ENV(env);
1622
+ CHECK_ARG(env, result);
1623
+
1624
+ auto isolate = env->isolate;
1625
+ auto str_maybe =
1626
+ v8::String::NewFromOneByte(isolate,
1627
+ reinterpret_cast<const uint8_t*>(str),
1628
+ v8::NewStringType::kInternalized,
1629
+ length);
1630
+ CHECK_MAYBE_EMPTY(env, str_maybe, napi_generic_failure);
1631
+
1632
+ *result = v8impl::JsValueFromV8LocalValue(str_maybe.ToLocalChecked());
1633
+ return napi_clear_last_error(env);
1634
+ }
1635
+
1636
+ napi_status napi_create_string_utf8(napi_env env,
1637
+ const char* str,
1638
+ size_t length,
1639
+ napi_value* result) {
1640
+ CHECK_ENV(env);
1641
+ CHECK_ARG(env, result);
1642
+
1643
+ v8::Local<v8::String> s;
1644
+ CHECK_NEW_FROM_UTF8_LEN(env, s, str, length);
1645
+
1646
+ *result = v8impl::JsValueFromV8LocalValue(s);
1647
+ return napi_clear_last_error(env);
1648
+ }
1649
+
1650
+ napi_status napi_create_string_utf16(napi_env env,
1651
+ const char16_t* str,
1652
+ size_t length,
1653
+ napi_value* result) {
1654
+ CHECK_ENV(env);
1655
+ CHECK_ARG(env, result);
1656
+
1657
+ auto isolate = env->isolate;
1658
+ auto str_maybe =
1659
+ v8::String::NewFromTwoByte(isolate,
1660
+ reinterpret_cast<const uint16_t*>(str),
1661
+ v8::NewStringType::kInternalized,
1662
+ length);
1663
+ CHECK_MAYBE_EMPTY(env, str_maybe, napi_generic_failure);
1664
+
1665
+ *result = v8impl::JsValueFromV8LocalValue(str_maybe.ToLocalChecked());
1666
+ return napi_clear_last_error(env);
1667
+ }
1668
+
1669
+ napi_status napi_create_double(napi_env env,
1670
+ double value,
1671
+ napi_value* result) {
1672
+ CHECK_ENV(env);
1673
+ CHECK_ARG(env, result);
1674
+
1675
+ *result = v8impl::JsValueFromV8LocalValue(
1676
+ v8::Number::New(env->isolate, value));
1677
+
1678
+ return napi_clear_last_error(env);
1679
+ }
1680
+
1681
+ napi_status napi_create_int32(napi_env env,
1682
+ int32_t value,
1683
+ napi_value* result) {
1684
+ CHECK_ENV(env);
1685
+ CHECK_ARG(env, result);
1686
+
1687
+ *result = v8impl::JsValueFromV8LocalValue(
1688
+ v8::Integer::New(env->isolate, value));
1689
+
1690
+ return napi_clear_last_error(env);
1691
+ }
1692
+
1693
+ napi_status napi_create_uint32(napi_env env,
1694
+ uint32_t value,
1695
+ napi_value* result) {
1696
+ CHECK_ENV(env);
1697
+ CHECK_ARG(env, result);
1698
+
1699
+ *result = v8impl::JsValueFromV8LocalValue(
1700
+ v8::Integer::NewFromUnsigned(env->isolate, value));
1701
+
1702
+ return napi_clear_last_error(env);
1703
+ }
1704
+
1705
+ napi_status napi_create_int64(napi_env env,
1706
+ int64_t value,
1707
+ napi_value* result) {
1708
+ CHECK_ENV(env);
1709
+ CHECK_ARG(env, result);
1710
+
1711
+ *result = v8impl::JsValueFromV8LocalValue(
1712
+ v8::Number::New(env->isolate, static_cast<double>(value)));
1713
+
1714
+ return napi_clear_last_error(env);
1715
+ }
1716
+
1717
+ napi_status napi_get_boolean(napi_env env, bool value, napi_value* result) {
1718
+ CHECK_ENV(env);
1719
+ CHECK_ARG(env, result);
1720
+
1721
+ v8::Isolate* isolate = env->isolate;
1722
+
1723
+ if (value) {
1724
+ *result = v8impl::JsValueFromV8LocalValue(v8::True(isolate));
1725
+ } else {
1726
+ *result = v8impl::JsValueFromV8LocalValue(v8::False(isolate));
1727
+ }
1728
+
1729
+ return napi_clear_last_error(env);
1730
+ }
1731
+
1732
+ napi_status napi_create_symbol(napi_env env,
1733
+ napi_value description,
1734
+ napi_value* result) {
1735
+ CHECK_ENV(env);
1736
+ CHECK_ARG(env, result);
1737
+
1738
+ v8::Isolate* isolate = env->isolate;
1739
+
1740
+ if (description == nullptr) {
1741
+ *result = v8impl::JsValueFromV8LocalValue(v8::Symbol::New(isolate));
1742
+ } else {
1743
+ v8::Local<v8::Value> desc = v8impl::V8LocalValueFromJsValue(description);
1744
+ RETURN_STATUS_IF_FALSE(env, desc->IsString(), napi_string_expected);
1745
+
1746
+ *result = v8impl::JsValueFromV8LocalValue(
1747
+ v8::Symbol::New(isolate, desc.As<v8::String>()));
1748
+ }
1749
+
1750
+ return napi_clear_last_error(env);
1751
+ }
1752
+
1753
+ static napi_status set_error_code(napi_env env,
1754
+ v8::Local<v8::Value> error,
1755
+ napi_value code,
1756
+ const char* code_cstring) {
1757
+ if ((code != nullptr) || (code_cstring != nullptr)) {
1758
+ v8::Isolate* isolate = env->isolate;
1759
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
1760
+ v8::Local<v8::Object> err_object = error.As<v8::Object>();
1761
+
1762
+ v8::Local<v8::Value> code_value = v8impl::V8LocalValueFromJsValue(code);
1763
+ if (code != nullptr) {
1764
+ code_value = v8impl::V8LocalValueFromJsValue(code);
1765
+ RETURN_STATUS_IF_FALSE(env, code_value->IsString(), napi_string_expected);
1766
+ } else {
1767
+ CHECK_NEW_FROM_UTF8(env, code_value, code_cstring);
1768
+ }
1769
+
1770
+ v8::Local<v8::Name> code_key;
1771
+ CHECK_NEW_FROM_UTF8(env, code_key, "code");
1772
+
1773
+ v8::Maybe<bool> set_maybe = err_object->Set(context, code_key, code_value);
1774
+ RETURN_STATUS_IF_FALSE(env,
1775
+ set_maybe.FromMaybe(false),
1776
+ napi_generic_failure);
1777
+
1778
+ // now update the name to be "name [code]" where name is the
1779
+ // original name and code is the code associated with the Error
1780
+ v8::Local<v8::String> name_string;
1781
+ CHECK_NEW_FROM_UTF8(env, name_string, "");
1782
+ v8::Local<v8::Name> name_key;
1783
+ CHECK_NEW_FROM_UTF8(env, name_key, "name");
1784
+
1785
+ auto maybe_name = err_object->Get(context, name_key);
1786
+ if (!maybe_name.IsEmpty()) {
1787
+ v8::Local<v8::Value> name = maybe_name.ToLocalChecked();
1788
+ if (name->IsString()) {
1789
+ name_string = v8::String::Concat(name_string, name.As<v8::String>());
1790
+ }
1791
+ }
1792
+ name_string = v8::String::Concat(name_string,
1793
+ FIXED_ONE_BYTE_STRING(isolate, " ["));
1794
+ name_string = v8::String::Concat(name_string, code_value.As<v8::String>());
1795
+ name_string = v8::String::Concat(name_string,
1796
+ FIXED_ONE_BYTE_STRING(isolate, "]"));
1797
+
1798
+ set_maybe = err_object->Set(context, name_key, name_string);
1799
+ RETURN_STATUS_IF_FALSE(env,
1800
+ set_maybe.FromMaybe(false),
1801
+ napi_generic_failure);
1802
+ }
1803
+ return napi_ok;
1804
+ }
1805
+
1806
+ napi_status napi_create_error(napi_env env,
1807
+ napi_value code,
1808
+ napi_value msg,
1809
+ napi_value* result) {
1810
+ CHECK_ENV(env);
1811
+ CHECK_ARG(env, msg);
1812
+ CHECK_ARG(env, result);
1813
+
1814
+ v8::Local<v8::Value> message_value = v8impl::V8LocalValueFromJsValue(msg);
1815
+ RETURN_STATUS_IF_FALSE(env, message_value->IsString(), napi_string_expected);
1816
+
1817
+ v8::Local<v8::Value> error_obj =
1818
+ v8::Exception::Error(message_value.As<v8::String>());
1819
+ napi_status status = set_error_code(env, error_obj, code, nullptr);
1820
+ if (status != napi_ok) return status;
1821
+
1822
+ *result = v8impl::JsValueFromV8LocalValue(error_obj);
1823
+
1824
+ return napi_clear_last_error(env);
1825
+ }
1826
+
1827
+ napi_status napi_create_type_error(napi_env env,
1828
+ napi_value code,
1829
+ napi_value msg,
1830
+ napi_value* result) {
1831
+ CHECK_ENV(env);
1832
+ CHECK_ARG(env, msg);
1833
+ CHECK_ARG(env, result);
1834
+
1835
+ v8::Local<v8::Value> message_value = v8impl::V8LocalValueFromJsValue(msg);
1836
+ RETURN_STATUS_IF_FALSE(env, message_value->IsString(), napi_string_expected);
1837
+
1838
+ v8::Local<v8::Value> error_obj =
1839
+ v8::Exception::TypeError(message_value.As<v8::String>());
1840
+ napi_status status = set_error_code(env, error_obj, code, nullptr);
1841
+ if (status != napi_ok) return status;
1842
+
1843
+ *result = v8impl::JsValueFromV8LocalValue(error_obj);
1844
+
1845
+ return napi_clear_last_error(env);
1846
+ }
1847
+
1848
+ napi_status napi_create_range_error(napi_env env,
1849
+ napi_value code,
1850
+ napi_value msg,
1851
+ napi_value* result) {
1852
+ CHECK_ENV(env);
1853
+ CHECK_ARG(env, msg);
1854
+ CHECK_ARG(env, result);
1855
+
1856
+ v8::Local<v8::Value> message_value = v8impl::V8LocalValueFromJsValue(msg);
1857
+ RETURN_STATUS_IF_FALSE(env, message_value->IsString(), napi_string_expected);
1858
+
1859
+ v8::Local<v8::Value> error_obj =
1860
+ v8::Exception::RangeError(message_value.As<v8::String>());
1861
+ napi_status status = set_error_code(env, error_obj, code, nullptr);
1862
+ if (status != napi_ok) return status;
1863
+
1864
+ *result = v8impl::JsValueFromV8LocalValue(error_obj);
1865
+
1866
+ return napi_clear_last_error(env);
1867
+ }
1868
+
1869
+ napi_status napi_typeof(napi_env env,
1870
+ napi_value value,
1871
+ napi_valuetype* result) {
1872
+ // Omit NAPI_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw
1873
+ // JS exceptions.
1874
+ CHECK_ENV(env);
1875
+ CHECK_ARG(env, value);
1876
+ CHECK_ARG(env, result);
1877
+
1878
+ v8::Local<v8::Value> v = v8impl::V8LocalValueFromJsValue(value);
1879
+
1880
+ if (v->IsNumber()) {
1881
+ *result = napi_number;
1882
+ } else if (v->IsString()) {
1883
+ *result = napi_string;
1884
+ } else if (v->IsFunction()) {
1885
+ // This test has to come before IsObject because IsFunction
1886
+ // implies IsObject
1887
+ *result = napi_function;
1888
+ } else if (v->IsExternal()) {
1889
+ // This test has to come before IsObject because IsExternal
1890
+ // implies IsObject
1891
+ *result = napi_external;
1892
+ } else if (v->IsObject()) {
1893
+ *result = napi_object;
1894
+ } else if (v->IsBoolean()) {
1895
+ *result = napi_boolean;
1896
+ } else if (v->IsUndefined()) {
1897
+ *result = napi_undefined;
1898
+ } else if (v->IsSymbol()) {
1899
+ *result = napi_symbol;
1900
+ } else if (v->IsNull()) {
1901
+ *result = napi_null;
1902
+ } else {
1903
+ // Should not get here unless V8 has added some new kind of value.
1904
+ return napi_set_last_error(env, napi_invalid_arg);
1905
+ }
1906
+
1907
+ return napi_clear_last_error(env);
1908
+ }
1909
+
1910
+ napi_status napi_get_undefined(napi_env env, napi_value* result) {
1911
+ CHECK_ENV(env);
1912
+ CHECK_ARG(env, result);
1913
+
1914
+ *result = v8impl::JsValueFromV8LocalValue(
1915
+ v8::Undefined(env->isolate));
1916
+
1917
+ return napi_clear_last_error(env);
1918
+ }
1919
+
1920
+ napi_status napi_get_null(napi_env env, napi_value* result) {
1921
+ CHECK_ENV(env);
1922
+ CHECK_ARG(env, result);
1923
+
1924
+ *result = v8impl::JsValueFromV8LocalValue(
1925
+ v8::Null(env->isolate));
1926
+
1927
+ return napi_clear_last_error(env);
1928
+ }
1929
+
1930
+ // Gets all callback info in a single call. (Ugly, but faster.)
1931
+ napi_status napi_get_cb_info(
1932
+ napi_env env, // [in] NAPI environment handle
1933
+ napi_callback_info cbinfo, // [in] Opaque callback-info handle
1934
+ size_t* argc, // [in-out] Specifies the size of the provided argv array
1935
+ // and receives the actual count of args.
1936
+ napi_value* argv, // [out] Array of values
1937
+ napi_value* this_arg, // [out] Receives the JS 'this' arg for the call
1938
+ void** data) { // [out] Receives the data pointer for the callback.
1939
+ CHECK_ENV(env);
1940
+ CHECK_ARG(env, cbinfo);
1941
+
1942
+ v8impl::CallbackWrapper* info =
1943
+ reinterpret_cast<v8impl::CallbackWrapper*>(cbinfo);
1944
+
1945
+ if (argv != nullptr) {
1946
+ CHECK_ARG(env, argc);
1947
+ info->Args(argv, *argc);
1948
+ }
1949
+ if (argc != nullptr) {
1950
+ *argc = info->ArgsLength();
1951
+ }
1952
+ if (this_arg != nullptr) {
1953
+ *this_arg = info->This();
1954
+ }
1955
+ if (data != nullptr) {
1956
+ *data = info->Data();
1957
+ }
1958
+
1959
+ return napi_clear_last_error(env);
1960
+ }
1961
+
1962
+ napi_status napi_get_new_target(napi_env env,
1963
+ napi_callback_info cbinfo,
1964
+ napi_value* result) {
1965
+ CHECK_ENV(env);
1966
+ CHECK_ARG(env, cbinfo);
1967
+ CHECK_ARG(env, result);
1968
+
1969
+ v8impl::CallbackWrapper* info =
1970
+ reinterpret_cast<v8impl::CallbackWrapper*>(cbinfo);
1971
+
1972
+ *result = info->GetNewTarget();
1973
+ return napi_clear_last_error(env);
1974
+ }
1975
+
1976
+ napi_status napi_call_function(napi_env env,
1977
+ napi_value recv,
1978
+ napi_value func,
1979
+ size_t argc,
1980
+ const napi_value* argv,
1981
+ napi_value* result) {
1982
+ NAPI_PREAMBLE(env);
1983
+ CHECK_ARG(env, recv);
1984
+ if (argc > 0) {
1985
+ CHECK_ARG(env, argv);
1986
+ }
1987
+
1988
+ v8::Isolate* isolate = env->isolate;
1989
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
1990
+
1991
+ v8::Local<v8::Value> v8recv = v8impl::V8LocalValueFromJsValue(recv);
1992
+
1993
+ v8::Local<v8::Function> v8func;
1994
+ CHECK_TO_FUNCTION(env, v8func, func);
1995
+
1996
+ auto maybe = v8func->Call(context, v8recv, argc,
1997
+ reinterpret_cast<v8::Local<v8::Value>*>(const_cast<napi_value*>(argv)));
1998
+
1999
+ if (try_catch.HasCaught()) {
2000
+ return napi_set_last_error(env, napi_pending_exception);
2001
+ } else {
2002
+ if (result != nullptr) {
2003
+ CHECK_MAYBE_EMPTY(env, maybe, napi_generic_failure);
2004
+ *result = v8impl::JsValueFromV8LocalValue(maybe.ToLocalChecked());
2005
+ }
2006
+ return napi_clear_last_error(env);
2007
+ }
2008
+ }
2009
+
2010
+ napi_status napi_get_global(napi_env env, napi_value* result) {
2011
+ CHECK_ENV(env);
2012
+ CHECK_ARG(env, result);
2013
+
2014
+ v8::Isolate* isolate = env->isolate;
2015
+ // TODO(ianhall): what if we need the global object from a different
2016
+ // context in the same isolate?
2017
+ // Should napi_env be the current context rather than the current isolate?
2018
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
2019
+ *result = v8impl::JsValueFromV8LocalValue(context->Global());
2020
+
2021
+ return napi_clear_last_error(env);
2022
+ }
2023
+
2024
+ napi_status napi_throw(napi_env env, napi_value error) {
2025
+ NAPI_PREAMBLE(env);
2026
+ CHECK_ARG(env, error);
2027
+
2028
+ v8::Isolate* isolate = env->isolate;
2029
+
2030
+ isolate->ThrowException(v8impl::V8LocalValueFromJsValue(error));
2031
+ // any VM calls after this point and before returning
2032
+ // to the javascript invoker will fail
2033
+ return napi_clear_last_error(env);
2034
+ }
2035
+
2036
+ napi_status napi_throw_error(napi_env env,
2037
+ const char* code,
2038
+ const char* msg) {
2039
+ NAPI_PREAMBLE(env);
2040
+
2041
+ v8::Isolate* isolate = env->isolate;
2042
+ v8::Local<v8::String> str;
2043
+ CHECK_NEW_FROM_UTF8(env, str, msg);
2044
+
2045
+ v8::Local<v8::Value> error_obj = v8::Exception::Error(str);
2046
+ napi_status status = set_error_code(env, error_obj, nullptr, code);
2047
+ if (status != napi_ok) return status;
2048
+
2049
+ isolate->ThrowException(error_obj);
2050
+ // any VM calls after this point and before returning
2051
+ // to the javascript invoker will fail
2052
+ return napi_clear_last_error(env);
2053
+ }
2054
+
2055
+ napi_status napi_throw_type_error(napi_env env,
2056
+ const char* code,
2057
+ const char* msg) {
2058
+ NAPI_PREAMBLE(env);
2059
+
2060
+ v8::Isolate* isolate = env->isolate;
2061
+ v8::Local<v8::String> str;
2062
+ CHECK_NEW_FROM_UTF8(env, str, msg);
2063
+
2064
+ v8::Local<v8::Value> error_obj = v8::Exception::TypeError(str);
2065
+ napi_status status = set_error_code(env, error_obj, nullptr, code);
2066
+ if (status != napi_ok) return status;
2067
+
2068
+ isolate->ThrowException(error_obj);
2069
+ // any VM calls after this point and before returning
2070
+ // to the javascript invoker will fail
2071
+ return napi_clear_last_error(env);
2072
+ }
2073
+
2074
+ napi_status napi_throw_range_error(napi_env env,
2075
+ const char* code,
2076
+ const char* msg) {
2077
+ NAPI_PREAMBLE(env);
2078
+
2079
+ v8::Isolate* isolate = env->isolate;
2080
+ v8::Local<v8::String> str;
2081
+ CHECK_NEW_FROM_UTF8(env, str, msg);
2082
+
2083
+ v8::Local<v8::Value> error_obj = v8::Exception::RangeError(str);
2084
+ napi_status status = set_error_code(env, error_obj, nullptr, code);
2085
+ if (status != napi_ok) return status;
2086
+
2087
+ isolate->ThrowException(error_obj);
2088
+ // any VM calls after this point and before returning
2089
+ // to the javascript invoker will fail
2090
+ return napi_clear_last_error(env);
2091
+ }
2092
+
2093
+ napi_status napi_is_error(napi_env env, napi_value value, bool* result) {
2094
+ // Omit NAPI_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot
2095
+ // throw JS exceptions.
2096
+ CHECK_ENV(env);
2097
+ CHECK_ARG(env, value);
2098
+ CHECK_ARG(env, result);
2099
+
2100
+ v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
2101
+ *result = val->IsNativeError();
2102
+
2103
+ return napi_clear_last_error(env);
2104
+ }
2105
+
2106
+ napi_status napi_get_value_double(napi_env env,
2107
+ napi_value value,
2108
+ double* result) {
2109
+ // Omit NAPI_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw
2110
+ // JS exceptions.
2111
+ CHECK_ENV(env);
2112
+ CHECK_ARG(env, value);
2113
+ CHECK_ARG(env, result);
2114
+
2115
+ v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
2116
+ RETURN_STATUS_IF_FALSE(env, val->IsNumber(), napi_number_expected);
2117
+
2118
+ *result = val.As<v8::Number>()->Value();
2119
+
2120
+ return napi_clear_last_error(env);
2121
+ }
2122
+
2123
+ napi_status napi_get_value_int32(napi_env env,
2124
+ napi_value value,
2125
+ int32_t* result) {
2126
+ // Omit NAPI_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw
2127
+ // JS exceptions.
2128
+ CHECK_ENV(env);
2129
+ CHECK_ARG(env, value);
2130
+ CHECK_ARG(env, result);
2131
+
2132
+ v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
2133
+
2134
+ if (val->IsInt32()) {
2135
+ *result = val.As<v8::Int32>()->Value();
2136
+ } else {
2137
+ RETURN_STATUS_IF_FALSE(env, val->IsNumber(), napi_number_expected);
2138
+
2139
+ // Empty context: https://github.com/nodejs/node/issues/14379
2140
+ v8::Local<v8::Context> context;
2141
+ *result = val->Int32Value(context).FromJust();
2142
+ }
2143
+
2144
+ return napi_clear_last_error(env);
2145
+ }
2146
+
2147
+ napi_status napi_get_value_uint32(napi_env env,
2148
+ napi_value value,
2149
+ uint32_t* result) {
2150
+ // Omit NAPI_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw
2151
+ // JS exceptions.
2152
+ CHECK_ENV(env);
2153
+ CHECK_ARG(env, value);
2154
+ CHECK_ARG(env, result);
2155
+
2156
+ v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
2157
+
2158
+ if (val->IsUint32()) {
2159
+ *result = val.As<v8::Uint32>()->Value();
2160
+ } else {
2161
+ RETURN_STATUS_IF_FALSE(env, val->IsNumber(), napi_number_expected);
2162
+
2163
+ // Empty context: https://github.com/nodejs/node/issues/14379
2164
+ v8::Local<v8::Context> context;
2165
+ *result = val->Uint32Value(context).FromJust();
2166
+ }
2167
+
2168
+ return napi_clear_last_error(env);
2169
+ }
2170
+
2171
+ napi_status napi_get_value_int64(napi_env env,
2172
+ napi_value value,
2173
+ int64_t* result) {
2174
+ // Omit NAPI_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw
2175
+ // JS exceptions.
2176
+ CHECK_ENV(env);
2177
+ CHECK_ARG(env, value);
2178
+ CHECK_ARG(env, result);
2179
+
2180
+ v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
2181
+
2182
+ // This is still a fast path very likely to be taken.
2183
+ if (val->IsInt32()) {
2184
+ *result = val.As<v8::Int32>()->Value();
2185
+ return napi_clear_last_error(env);
2186
+ }
2187
+
2188
+ RETURN_STATUS_IF_FALSE(env, val->IsNumber(), napi_number_expected);
2189
+
2190
+ // v8::Value::IntegerValue() converts NaN to INT64_MIN, inconsistent with
2191
+ // v8::Value::Int32Value() that converts NaN to 0. So special-case NaN here.
2192
+ double doubleValue = val.As<v8::Number>()->Value();
2193
+ if (std::isnan(doubleValue)) {
2194
+ *result = 0;
2195
+ } else {
2196
+ // Empty context: https://github.com/nodejs/node/issues/14379
2197
+ v8::Local<v8::Context> context;
2198
+ *result = val->IntegerValue(context).FromJust();
2199
+ }
2200
+
2201
+ return napi_clear_last_error(env);
2202
+ }
2203
+
2204
+ napi_status napi_get_value_bool(napi_env env, napi_value value, bool* result) {
2205
+ // Omit NAPI_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw
2206
+ // JS exceptions.
2207
+ CHECK_ENV(env);
2208
+ CHECK_ARG(env, value);
2209
+ CHECK_ARG(env, result);
2210
+
2211
+ v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
2212
+ RETURN_STATUS_IF_FALSE(env, val->IsBoolean(), napi_boolean_expected);
2213
+
2214
+ *result = val.As<v8::Boolean>()->Value();
2215
+
2216
+ return napi_clear_last_error(env);
2217
+ }
2218
+
2219
+ // Copies a JavaScript string into a LATIN-1 string buffer. The result is the
2220
+ // number of bytes (excluding the null terminator) copied into buf.
2221
+ // A sufficient buffer size should be greater than the length of string,
2222
+ // reserving space for null terminator.
2223
+ // If bufsize is insufficient, the string will be truncated and null terminated.
2224
+ // If buf is NULL, this method returns the length of the string (in bytes)
2225
+ // via the result parameter.
2226
+ // The result argument is optional unless buf is NULL.
2227
+ napi_status napi_get_value_string_latin1(napi_env env,
2228
+ napi_value value,
2229
+ char* buf,
2230
+ size_t bufsize,
2231
+ size_t* result) {
2232
+ CHECK_ENV(env);
2233
+ CHECK_ARG(env, value);
2234
+
2235
+ v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
2236
+ RETURN_STATUS_IF_FALSE(env, val->IsString(), napi_string_expected);
2237
+
2238
+ if (!buf) {
2239
+ CHECK_ARG(env, result);
2240
+ *result = val.As<v8::String>()->Length();
2241
+ } else if (bufsize != 0) {
2242
+ int copied = val.As<v8::String>()->WriteOneByte(
2243
+ reinterpret_cast<uint8_t*>(buf), 0, bufsize - 1,
2244
+ v8::String::NO_NULL_TERMINATION);
2245
+
2246
+ buf[copied] = '\0';
2247
+ if (result != nullptr) {
2248
+ *result = copied;
2249
+ }
2250
+ } else if (result != nullptr) {
2251
+ *result = 0;
2252
+ }
2253
+
2254
+ return napi_clear_last_error(env);
2255
+ }
2256
+
2257
+ // Copies a JavaScript string into a UTF-8 string buffer. The result is the
2258
+ // number of bytes (excluding the null terminator) copied into buf.
2259
+ // A sufficient buffer size should be greater than the length of string,
2260
+ // reserving space for null terminator.
2261
+ // If bufsize is insufficient, the string will be truncated and null terminated.
2262
+ // If buf is NULL, this method returns the length of the string (in bytes)
2263
+ // via the result parameter.
2264
+ // The result argument is optional unless buf is NULL.
2265
+ napi_status napi_get_value_string_utf8(napi_env env,
2266
+ napi_value value,
2267
+ char* buf,
2268
+ size_t bufsize,
2269
+ size_t* result) {
2270
+ CHECK_ENV(env);
2271
+ CHECK_ARG(env, value);
2272
+
2273
+ v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
2274
+ RETURN_STATUS_IF_FALSE(env, val->IsString(), napi_string_expected);
2275
+
2276
+ if (!buf) {
2277
+ CHECK_ARG(env, result);
2278
+ *result = val.As<v8::String>()->Utf8Length();
2279
+ } else if (bufsize != 0) {
2280
+ int copied = val.As<v8::String>()->WriteUtf8(
2281
+ buf, bufsize - 1, nullptr, v8::String::REPLACE_INVALID_UTF8 |
2282
+ v8::String::NO_NULL_TERMINATION);
2283
+
2284
+ buf[copied] = '\0';
2285
+ if (result != nullptr) {
2286
+ *result = copied;
2287
+ }
2288
+ } else if (result != nullptr) {
2289
+ *result = 0;
2290
+ }
2291
+
2292
+ return napi_clear_last_error(env);
2293
+ }
2294
+
2295
+ // Copies a JavaScript string into a UTF-16 string buffer. The result is the
2296
+ // number of 2-byte code units (excluding the null terminator) copied into buf.
2297
+ // A sufficient buffer size should be greater than the length of string,
2298
+ // reserving space for null terminator.
2299
+ // If bufsize is insufficient, the string will be truncated and null terminated.
2300
+ // If buf is NULL, this method returns the length of the string (in 2-byte
2301
+ // code units) via the result parameter.
2302
+ // The result argument is optional unless buf is NULL.
2303
+ napi_status napi_get_value_string_utf16(napi_env env,
2304
+ napi_value value,
2305
+ char16_t* buf,
2306
+ size_t bufsize,
2307
+ size_t* result) {
2308
+ CHECK_ENV(env);
2309
+ CHECK_ARG(env, value);
2310
+
2311
+ v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
2312
+ RETURN_STATUS_IF_FALSE(env, val->IsString(), napi_string_expected);
2313
+
2314
+ if (!buf) {
2315
+ CHECK_ARG(env, result);
2316
+ // V8 assumes UTF-16 length is the same as the number of characters.
2317
+ *result = val.As<v8::String>()->Length();
2318
+ } else if (bufsize != 0) {
2319
+ int copied = val.As<v8::String>()->Write(
2320
+ reinterpret_cast<uint16_t*>(buf), 0, bufsize - 1,
2321
+ v8::String::NO_NULL_TERMINATION);
2322
+
2323
+ buf[copied] = '\0';
2324
+ if (result != nullptr) {
2325
+ *result = copied;
2326
+ }
2327
+ } else if (result != nullptr) {
2328
+ *result = 0;
2329
+ }
2330
+
2331
+ return napi_clear_last_error(env);
2332
+ }
2333
+
2334
+ napi_status napi_coerce_to_object(napi_env env,
2335
+ napi_value value,
2336
+ napi_value* result) {
2337
+ NAPI_PREAMBLE(env);
2338
+ CHECK_ARG(env, value);
2339
+ CHECK_ARG(env, result);
2340
+
2341
+ v8::Isolate* isolate = env->isolate;
2342
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
2343
+ v8::Local<v8::Object> obj;
2344
+ CHECK_TO_OBJECT(env, context, obj, value);
2345
+
2346
+ *result = v8impl::JsValueFromV8LocalValue(obj);
2347
+ return GET_RETURN_STATUS(env);
2348
+ }
2349
+
2350
+ napi_status napi_coerce_to_bool(napi_env env,
2351
+ napi_value value,
2352
+ napi_value* result) {
2353
+ NAPI_PREAMBLE(env);
2354
+ CHECK_ARG(env, value);
2355
+ CHECK_ARG(env, result);
2356
+
2357
+ v8::Isolate* isolate = env->isolate;
2358
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
2359
+ v8::Local<v8::Boolean> b;
2360
+
2361
+ CHECK_TO_BOOL(env, context, b, value);
2362
+
2363
+ *result = v8impl::JsValueFromV8LocalValue(b);
2364
+ return GET_RETURN_STATUS(env);
2365
+ }
2366
+
2367
+ napi_status napi_coerce_to_number(napi_env env,
2368
+ napi_value value,
2369
+ napi_value* result) {
2370
+ NAPI_PREAMBLE(env);
2371
+ CHECK_ARG(env, value);
2372
+ CHECK_ARG(env, result);
2373
+
2374
+ v8::Isolate* isolate = env->isolate;
2375
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
2376
+ v8::Local<v8::Number> num;
2377
+
2378
+ CHECK_TO_NUMBER(env, context, num, value);
2379
+
2380
+ *result = v8impl::JsValueFromV8LocalValue(num);
2381
+ return GET_RETURN_STATUS(env);
2382
+ }
2383
+
2384
+ napi_status napi_coerce_to_string(napi_env env,
2385
+ napi_value value,
2386
+ napi_value* result) {
2387
+ NAPI_PREAMBLE(env);
2388
+ CHECK_ARG(env, value);
2389
+ CHECK_ARG(env, result);
2390
+
2391
+ v8::Isolate* isolate = env->isolate;
2392
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
2393
+ v8::Local<v8::String> str;
2394
+
2395
+ CHECK_TO_STRING(env, context, str, value);
2396
+
2397
+ *result = v8impl::JsValueFromV8LocalValue(str);
2398
+ return GET_RETURN_STATUS(env);
2399
+ }
2400
+
2401
+ napi_status napi_wrap(napi_env env,
2402
+ napi_value js_object,
2403
+ void* native_object,
2404
+ napi_finalize finalize_cb,
2405
+ void* finalize_hint,
2406
+ napi_ref* result) {
2407
+ NAPI_PREAMBLE(env);
2408
+ CHECK_ARG(env, js_object);
2409
+
2410
+ v8::Isolate* isolate = env->isolate;
2411
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
2412
+
2413
+ v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(js_object);
2414
+ RETURN_STATUS_IF_FALSE(env, value->IsObject(), napi_invalid_arg);
2415
+ v8::Local<v8::Object> obj = value.As<v8::Object>();
2416
+
2417
+ // If we've already wrapped this object, we error out.
2418
+ RETURN_STATUS_IF_FALSE(env, !v8impl::FindWrapper(obj), napi_invalid_arg);
2419
+
2420
+ // Create a wrapper object with an internal field to hold the wrapped pointer
2421
+ // and a second internal field to identify the owner as N-API.
2422
+ v8::Local<v8::ObjectTemplate> wrapper_template;
2423
+ ENV_OBJECT_TEMPLATE(env, wrap, wrapper_template, v8impl::kWrapperFields);
2424
+
2425
+ auto maybe_object = wrapper_template->NewInstance(context);
2426
+ CHECK_MAYBE_EMPTY(env, maybe_object, napi_generic_failure);
2427
+ v8::Local<v8::Object> wrapper = maybe_object.ToLocalChecked();
2428
+
2429
+ // Store the pointer as an external in the wrapper.
2430
+ wrapper->SetInternalField(0, v8::External::New(isolate, native_object));
2431
+ wrapper->SetInternalField(1, v8::External::New(isolate,
2432
+ reinterpret_cast<void*>(const_cast<char*>(v8impl::napi_wrap_name))));
2433
+
2434
+ // Insert the wrapper into the object's prototype chain.
2435
+ v8::Local<v8::Value> proto = obj->GetPrototype();
2436
+ CHECK(wrapper->SetPrototype(context, proto).FromJust());
2437
+ CHECK(obj->SetPrototype(context, wrapper).FromJust());
2438
+
2439
+ v8impl::Reference* reference = nullptr;
2440
+ if (result != nullptr) {
2441
+ // The returned reference should be deleted via napi_delete_reference()
2442
+ // ONLY in response to the finalize callback invocation. (If it is deleted
2443
+ // before then, then the finalize callback will never be invoked.)
2444
+ // Therefore a finalize callback is required when returning a reference.
2445
+ CHECK_ARG(env, finalize_cb);
2446
+ reference = v8impl::Reference::New(
2447
+ env, obj, 0, false, finalize_cb, native_object, finalize_hint);
2448
+ *result = reinterpret_cast<napi_ref>(reference);
2449
+ } else if (finalize_cb != nullptr) {
2450
+ // Create a self-deleting reference just for the finalize callback.
2451
+ reference = v8impl::Reference::New(
2452
+ env, obj, 0, true, finalize_cb, native_object, finalize_hint);
2453
+ }
2454
+
2455
+ if (reference != nullptr) {
2456
+ wrapper->SetInternalField(2, v8::External::New(isolate, reference));
2457
+ }
2458
+
2459
+ return GET_RETURN_STATUS(env);
2460
+ }
2461
+
2462
+ napi_status napi_unwrap(napi_env env, napi_value obj, void** result) {
2463
+ // Omit NAPI_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw
2464
+ // JS exceptions.
2465
+ CHECK_ENV(env);
2466
+ v8::Local<v8::Object> wrapper;
2467
+ return napi_set_last_error(env, v8impl::Unwrap(env, obj, result, &wrapper));
2468
+ }
2469
+
2470
+ napi_status napi_remove_wrap(napi_env env, napi_value obj, void** result) {
2471
+ NAPI_PREAMBLE(env);
2472
+ v8::Local<v8::Object> wrapper;
2473
+ v8::Local<v8::Object> parent;
2474
+ napi_status status = v8impl::Unwrap(env, obj, result, &wrapper, &parent);
2475
+ if (status != napi_ok) {
2476
+ return napi_set_last_error(env, status);
2477
+ }
2478
+
2479
+ v8::Local<v8::Value> external = wrapper->GetInternalField(2);
2480
+ if (external->IsExternal()) {
2481
+ v8impl::Reference::Delete(
2482
+ static_cast<v8impl::Reference*>(external.As<v8::External>()->Value()));
2483
+ }
2484
+
2485
+ if (!parent.IsEmpty()) {
2486
+ v8::Maybe<bool> maybe = parent->SetPrototype(
2487
+ env->isolate->GetCurrentContext(), wrapper->GetPrototype());
2488
+ CHECK_MAYBE_NOTHING(env, maybe, napi_generic_failure);
2489
+ if (!maybe.FromMaybe(false)) {
2490
+ return napi_set_last_error(env, napi_generic_failure);
2491
+ }
2492
+ }
2493
+
2494
+ return GET_RETURN_STATUS(env);
2495
+ }
2496
+
2497
+ napi_status napi_create_external(napi_env env,
2498
+ void* data,
2499
+ napi_finalize finalize_cb,
2500
+ void* finalize_hint,
2501
+ napi_value* result) {
2502
+ NAPI_PREAMBLE(env);
2503
+ CHECK_ARG(env, result);
2504
+
2505
+ v8::Isolate* isolate = env->isolate;
2506
+
2507
+ v8::Local<v8::Value> external_value = v8::External::New(isolate, data);
2508
+
2509
+ // The Reference object will delete itself after invoking the finalizer
2510
+ // callback.
2511
+ v8impl::Reference::New(env,
2512
+ external_value,
2513
+ 0,
2514
+ true,
2515
+ finalize_cb,
2516
+ data,
2517
+ finalize_hint);
2518
+
2519
+ *result = v8impl::JsValueFromV8LocalValue(external_value);
2520
+
2521
+ return napi_clear_last_error(env);
2522
+ }
2523
+
2524
+ napi_status napi_get_value_external(napi_env env,
2525
+ napi_value value,
2526
+ void** result) {
2527
+ CHECK_ENV(env);
2528
+ CHECK_ARG(env, value);
2529
+ CHECK_ARG(env, result);
2530
+
2531
+ v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
2532
+ RETURN_STATUS_IF_FALSE(env, val->IsExternal(), napi_invalid_arg);
2533
+
2534
+ v8::Local<v8::External> external_value = val.As<v8::External>();
2535
+ *result = external_value->Value();
2536
+
2537
+ return napi_clear_last_error(env);
2538
+ }
2539
+
2540
+ // Set initial_refcount to 0 for a weak reference, >0 for a strong reference.
2541
+ napi_status napi_create_reference(napi_env env,
2542
+ napi_value value,
2543
+ uint32_t initial_refcount,
2544
+ napi_ref* result) {
2545
+ // Omit NAPI_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw
2546
+ // JS exceptions.
2547
+ CHECK_ENV(env);
2548
+ CHECK_ARG(env, value);
2549
+ CHECK_ARG(env, result);
2550
+
2551
+ v8::Local<v8::Value> v8_value = v8impl::V8LocalValueFromJsValue(value);
2552
+
2553
+ if (!(v8_value->IsObject() || v8_value->IsFunction())) {
2554
+ return napi_set_last_error(env, napi_object_expected);
2555
+ }
2556
+
2557
+ v8impl::Reference* reference =
2558
+ v8impl::Reference::New(env, v8_value, initial_refcount, false);
2559
+
2560
+ *result = reinterpret_cast<napi_ref>(reference);
2561
+ return napi_clear_last_error(env);
2562
+ }
2563
+
2564
+ // Deletes a reference. The referenced value is released, and may be GC'd unless
2565
+ // there are other references to it.
2566
+ napi_status napi_delete_reference(napi_env env, napi_ref ref) {
2567
+ // Omit NAPI_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw
2568
+ // JS exceptions.
2569
+ CHECK_ENV(env);
2570
+ CHECK_ARG(env, ref);
2571
+
2572
+ v8impl::Reference::Delete(reinterpret_cast<v8impl::Reference*>(ref));
2573
+
2574
+ return napi_clear_last_error(env);
2575
+ }
2576
+
2577
+ // Increments the reference count, optionally returning the resulting count.
2578
+ // After this call the reference will be a strong reference because its
2579
+ // refcount is >0, and the referenced object is effectively "pinned".
2580
+ // Calling this when the refcount is 0 and the object is unavailable
2581
+ // results in an error.
2582
+ napi_status napi_reference_ref(napi_env env, napi_ref ref, uint32_t* result) {
2583
+ // Omit NAPI_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw
2584
+ // JS exceptions.
2585
+ CHECK_ENV(env);
2586
+ CHECK_ARG(env, ref);
2587
+
2588
+ v8impl::Reference* reference = reinterpret_cast<v8impl::Reference*>(ref);
2589
+ uint32_t count = reference->Ref();
2590
+
2591
+ if (result != nullptr) {
2592
+ *result = count;
2593
+ }
2594
+
2595
+ return napi_clear_last_error(env);
2596
+ }
2597
+
2598
+ // Decrements the reference count, optionally returning the resulting count. If
2599
+ // the result is 0 the reference is now weak and the object may be GC'd at any
2600
+ // time if there are no other references. Calling this when the refcount is
2601
+ // already 0 results in an error.
2602
+ napi_status napi_reference_unref(napi_env env, napi_ref ref, uint32_t* result) {
2603
+ // Omit NAPI_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw
2604
+ // JS exceptions.
2605
+ CHECK_ENV(env);
2606
+ CHECK_ARG(env, ref);
2607
+
2608
+ v8impl::Reference* reference = reinterpret_cast<v8impl::Reference*>(ref);
2609
+
2610
+ if (reference->RefCount() == 0) {
2611
+ return napi_set_last_error(env, napi_generic_failure);
2612
+ }
2613
+
2614
+ uint32_t count = reference->Unref();
2615
+
2616
+ if (result != nullptr) {
2617
+ *result = count;
2618
+ }
2619
+
2620
+ return napi_clear_last_error(env);
2621
+ }
2622
+
2623
+ // Attempts to get a referenced value. If the reference is weak, the value might
2624
+ // no longer be available, in that case the call is still successful but the
2625
+ // result is NULL.
2626
+ napi_status napi_get_reference_value(napi_env env,
2627
+ napi_ref ref,
2628
+ napi_value* result) {
2629
+ // Omit NAPI_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw
2630
+ // JS exceptions.
2631
+ CHECK_ENV(env);
2632
+ CHECK_ARG(env, ref);
2633
+ CHECK_ARG(env, result);
2634
+
2635
+ v8impl::Reference* reference = reinterpret_cast<v8impl::Reference*>(ref);
2636
+ *result = v8impl::JsValueFromV8LocalValue(reference->Get());
2637
+
2638
+ return napi_clear_last_error(env);
2639
+ }
2640
+
2641
+ napi_status napi_open_handle_scope(napi_env env, napi_handle_scope* result) {
2642
+ // Omit NAPI_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw
2643
+ // JS exceptions.
2644
+ CHECK_ENV(env);
2645
+ CHECK_ARG(env, result);
2646
+
2647
+ *result = v8impl::JsHandleScopeFromV8HandleScope(
2648
+ new v8impl::HandleScopeWrapper(env->isolate));
2649
+ env->open_handle_scopes++;
2650
+ return napi_clear_last_error(env);
2651
+ }
2652
+
2653
+ napi_status napi_close_handle_scope(napi_env env, napi_handle_scope scope) {
2654
+ // Omit NAPI_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw
2655
+ // JS exceptions.
2656
+ CHECK_ENV(env);
2657
+ CHECK_ARG(env, scope);
2658
+ if (env->open_handle_scopes == 0) {
2659
+ return napi_handle_scope_mismatch;
2660
+ }
2661
+
2662
+ env->open_handle_scopes--;
2663
+ delete v8impl::V8HandleScopeFromJsHandleScope(scope);
2664
+ return napi_clear_last_error(env);
2665
+ }
2666
+
2667
+ napi_status napi_open_escapable_handle_scope(
2668
+ napi_env env,
2669
+ napi_escapable_handle_scope* result) {
2670
+ // Omit NAPI_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw
2671
+ // JS exceptions.
2672
+ CHECK_ENV(env);
2673
+ CHECK_ARG(env, result);
2674
+
2675
+ *result = v8impl::JsEscapableHandleScopeFromV8EscapableHandleScope(
2676
+ new v8impl::EscapableHandleScopeWrapper(env->isolate));
2677
+ env->open_handle_scopes++;
2678
+ return napi_clear_last_error(env);
2679
+ }
2680
+
2681
+ napi_status napi_close_escapable_handle_scope(
2682
+ napi_env env,
2683
+ napi_escapable_handle_scope scope) {
2684
+ // Omit NAPI_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw
2685
+ // JS exceptions.
2686
+ CHECK_ENV(env);
2687
+ CHECK_ARG(env, scope);
2688
+ if (env->open_handle_scopes == 0) {
2689
+ return napi_handle_scope_mismatch;
2690
+ }
2691
+
2692
+ delete v8impl::V8EscapableHandleScopeFromJsEscapableHandleScope(scope);
2693
+ env->open_handle_scopes--;
2694
+ return napi_clear_last_error(env);
2695
+ }
2696
+
2697
+ napi_status napi_escape_handle(napi_env env,
2698
+ napi_escapable_handle_scope scope,
2699
+ napi_value escapee,
2700
+ napi_value* result) {
2701
+ // Omit NAPI_PREAMBLE and GET_RETURN_STATUS because V8 calls here cannot throw
2702
+ // JS exceptions.
2703
+ CHECK_ENV(env);
2704
+ CHECK_ARG(env, scope);
2705
+ CHECK_ARG(env, escapee);
2706
+ CHECK_ARG(env, result);
2707
+
2708
+ v8impl::EscapableHandleScopeWrapper* s =
2709
+ v8impl::V8EscapableHandleScopeFromJsEscapableHandleScope(scope);
2710
+ if (!s->escape_called()) {
2711
+ *result = v8impl::JsValueFromV8LocalValue(
2712
+ s->Escape(v8impl::V8LocalValueFromJsValue(escapee)));
2713
+ return napi_clear_last_error(env);
2714
+ }
2715
+ return napi_set_last_error(env, napi_escape_called_twice);
2716
+ }
2717
+
2718
+ napi_status napi_new_instance(napi_env env,
2719
+ napi_value constructor,
2720
+ size_t argc,
2721
+ const napi_value* argv,
2722
+ napi_value* result) {
2723
+ NAPI_PREAMBLE(env);
2724
+ CHECK_ARG(env, constructor);
2725
+ if (argc > 0) {
2726
+ CHECK_ARG(env, argv);
2727
+ }
2728
+ CHECK_ARG(env, result);
2729
+
2730
+ v8::Isolate* isolate = env->isolate;
2731
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
2732
+
2733
+ v8::Local<v8::Function> ctor;
2734
+ CHECK_TO_FUNCTION(env, ctor, constructor);
2735
+
2736
+ auto maybe = ctor->NewInstance(context, argc,
2737
+ reinterpret_cast<v8::Local<v8::Value>*>(const_cast<napi_value*>(argv)));
2738
+
2739
+ CHECK_MAYBE_EMPTY(env, maybe, napi_generic_failure);
2740
+
2741
+ *result = v8impl::JsValueFromV8LocalValue(maybe.ToLocalChecked());
2742
+ return GET_RETURN_STATUS(env);
2743
+ }
2744
+
2745
+ napi_status napi_instanceof(napi_env env,
2746
+ napi_value object,
2747
+ napi_value constructor,
2748
+ bool* result) {
2749
+ NAPI_PREAMBLE(env);
2750
+ CHECK_ARG(env, object);
2751
+ CHECK_ARG(env, result);
2752
+
2753
+ *result = false;
2754
+
2755
+ v8::Local<v8::Object> ctor;
2756
+ v8::Isolate* isolate = env->isolate;
2757
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
2758
+
2759
+ CHECK_TO_OBJECT(env, context, ctor, constructor);
2760
+
2761
+ if (!ctor->IsFunction()) {
2762
+ napi_throw_type_error(env,
2763
+ "ERR_NAPI_CONS_FUNCTION",
2764
+ "Constructor must be a function");
2765
+
2766
+ return napi_set_last_error(env, napi_function_expected);
2767
+ }
2768
+
2769
+ if (env->has_instance_available) {
2770
+ napi_value value, js_result = nullptr, has_instance = nullptr;
2771
+ napi_status status = napi_generic_failure;
2772
+ napi_valuetype value_type;
2773
+
2774
+ // Get "Symbol" from the global object
2775
+ if (env->has_instance.IsEmpty()) {
2776
+ status = napi_get_global(env, &value);
2777
+ if (status != napi_ok) return status;
2778
+ status = napi_get_named_property(env, value, "Symbol", &value);
2779
+ if (status != napi_ok) return status;
2780
+ status = napi_typeof(env, value, &value_type);
2781
+ if (status != napi_ok) return status;
2782
+
2783
+ // Get "hasInstance" from Symbol
2784
+ if (value_type == napi_function) {
2785
+ status = napi_get_named_property(env, value, "hasInstance", &value);
2786
+ if (status != napi_ok) return status;
2787
+ status = napi_typeof(env, value, &value_type);
2788
+ if (status != napi_ok) return status;
2789
+
2790
+ // Store Symbol.hasInstance in a global persistent reference
2791
+ if (value_type == napi_symbol) {
2792
+ env->has_instance.Reset(env->isolate,
2793
+ v8impl::V8LocalValueFromJsValue(value));
2794
+ has_instance = value;
2795
+ }
2796
+ }
2797
+ } else {
2798
+ has_instance = v8impl::JsValueFromV8LocalValue(
2799
+ v8::Local<v8::Value>::New(env->isolate, env->has_instance));
2800
+ }
2801
+
2802
+ if (has_instance) {
2803
+ status = napi_get_property(env, constructor, has_instance, &value);
2804
+ if (status != napi_ok) return status;
2805
+ status = napi_typeof(env, value, &value_type);
2806
+ if (status != napi_ok) return status;
2807
+
2808
+ // Call the function to determine whether the object is an instance of the
2809
+ // constructor
2810
+ if (value_type == napi_function) {
2811
+ status = napi_call_function(env, constructor, value, 1, &object,
2812
+ &js_result);
2813
+ if (status != napi_ok) return status;
2814
+ return napi_get_value_bool(env, js_result, result);
2815
+ }
2816
+ }
2817
+
2818
+ env->has_instance_available = false;
2819
+ }
2820
+
2821
+ // If running constructor[Symbol.hasInstance](object) did not work, we perform
2822
+ // a traditional instanceof (early Node.js 6.x).
2823
+
2824
+ v8::Local<v8::String> prototype_string;
2825
+ CHECK_NEW_FROM_UTF8(env, prototype_string, "prototype");
2826
+
2827
+ auto maybe_prototype = ctor->Get(context, prototype_string);
2828
+ CHECK_MAYBE_EMPTY(env, maybe_prototype, napi_generic_failure);
2829
+
2830
+ v8::Local<v8::Value> prototype_property = maybe_prototype.ToLocalChecked();
2831
+ if (!prototype_property->IsObject()) {
2832
+ napi_throw_type_error(
2833
+ env,
2834
+ "ERR_NAPI_CONS_PROTOTYPE_OBJECT",
2835
+ "Constructor.prototype must be an object");
2836
+
2837
+ return napi_set_last_error(env, napi_object_expected);
2838
+ }
2839
+
2840
+ auto maybe_ctor = prototype_property->ToObject(context);
2841
+ CHECK_MAYBE_EMPTY(env, maybe_ctor, napi_generic_failure);
2842
+ ctor = maybe_ctor.ToLocalChecked();
2843
+
2844
+ v8::Local<v8::Value> current_obj = v8impl::V8LocalValueFromJsValue(object);
2845
+ if (!current_obj->StrictEquals(ctor)) {
2846
+ for (v8::Local<v8::Value> original_obj = current_obj;
2847
+ !(current_obj->IsNull() || current_obj->IsUndefined());) {
2848
+ if (current_obj->StrictEquals(ctor)) {
2849
+ *result = !(original_obj->IsNumber() ||
2850
+ original_obj->IsBoolean() ||
2851
+ original_obj->IsString());
2852
+ break;
2853
+ }
2854
+ v8::Local<v8::Object> obj;
2855
+ CHECK_TO_OBJECT(env, context, obj, v8impl::JsValueFromV8LocalValue(
2856
+ current_obj));
2857
+ current_obj = obj->GetPrototype();
2858
+ }
2859
+ }
2860
+
2861
+ return GET_RETURN_STATUS(env);
2862
+ }
2863
+
2864
+ napi_status napi_async_init(napi_env env,
2865
+ napi_value async_resource,
2866
+ napi_value async_resource_name,
2867
+ napi_async_context* result) {
2868
+ CHECK_ENV(env);
2869
+ CHECK_ARG(env, async_resource_name);
2870
+ CHECK_ARG(env, result);
2871
+
2872
+ v8::Isolate* isolate = env->isolate;
2873
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
2874
+
2875
+ v8::Local<v8::Object> v8_resource;
2876
+ if (async_resource != nullptr) {
2877
+ CHECK_TO_OBJECT(env, context, v8_resource, async_resource);
2878
+ } else {
2879
+ v8_resource = v8::Object::New(isolate);
2880
+ }
2881
+
2882
+ v8::Local<v8::String> v8_resource_name;
2883
+ CHECK_TO_STRING(env, context, v8_resource_name, async_resource_name);
2884
+
2885
+ // TODO(jasongin): Consider avoiding allocation here by using
2886
+ // a tagged pointer with 2×31 bit fields instead.
2887
+ node::async_context* async_context = new node::async_context();
2888
+
2889
+ *async_context = node::EmitAsyncInit(isolate, v8_resource, v8_resource_name);
2890
+ *result = reinterpret_cast<napi_async_context>(async_context);
2891
+
2892
+ return napi_clear_last_error(env);
2893
+ }
2894
+
2895
+ napi_status napi_async_destroy(napi_env env,
2896
+ napi_async_context async_context) {
2897
+ CHECK_ENV(env);
2898
+ CHECK_ARG(env, async_context);
2899
+
2900
+ v8::Isolate* isolate = env->isolate;
2901
+ node::async_context* node_async_context =
2902
+ reinterpret_cast<node::async_context*>(async_context);
2903
+ node::EmitAsyncDestroy(isolate, *node_async_context);
2904
+
2905
+ delete node_async_context;
2906
+
2907
+ return napi_clear_last_error(env);
2908
+ }
2909
+
2910
+ napi_status napi_make_callback(napi_env env,
2911
+ napi_async_context async_context,
2912
+ napi_value recv,
2913
+ napi_value func,
2914
+ size_t argc,
2915
+ const napi_value* argv,
2916
+ napi_value* result) {
2917
+ NAPI_PREAMBLE(env);
2918
+ CHECK_ARG(env, recv);
2919
+ if (argc > 0) {
2920
+ CHECK_ARG(env, argv);
2921
+ }
2922
+
2923
+ v8::Isolate* isolate = env->isolate;
2924
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
2925
+
2926
+ v8::Local<v8::Object> v8recv;
2927
+ CHECK_TO_OBJECT(env, context, v8recv, recv);
2928
+
2929
+ v8::Local<v8::Function> v8func;
2930
+ CHECK_TO_FUNCTION(env, v8func, func);
2931
+
2932
+ node::async_context* node_async_context =
2933
+ reinterpret_cast<node::async_context*>(async_context);
2934
+ if (node_async_context == nullptr) {
2935
+ static node::async_context empty_context = { 0, 0 };
2936
+ node_async_context = &empty_context;
2937
+ }
2938
+
2939
+ v8::MaybeLocal<v8::Value> callback_result = node::MakeCallback(
2940
+ isolate, v8recv, v8func, argc,
2941
+ reinterpret_cast<v8::Local<v8::Value>*>(const_cast<napi_value*>(argv)),
2942
+ *node_async_context);
2943
+ CHECK_MAYBE_EMPTY(env, callback_result, napi_generic_failure);
2944
+
2945
+ if (result != nullptr) {
2946
+ *result = v8impl::JsValueFromV8LocalValue(
2947
+ callback_result.ToLocalChecked());
2948
+ }
2949
+
2950
+ return GET_RETURN_STATUS(env);
2951
+ }
2952
+
2953
+ // Methods to support catching exceptions
2954
+ napi_status napi_is_exception_pending(napi_env env, bool* result) {
2955
+ // NAPI_PREAMBLE is not used here: this function must execute when there is a
2956
+ // pending exception.
2957
+ CHECK_ENV(env);
2958
+ CHECK_ARG(env, result);
2959
+
2960
+ *result = !env->last_exception.IsEmpty();
2961
+ return napi_clear_last_error(env);
2962
+ }
2963
+
2964
+ napi_status napi_get_and_clear_last_exception(napi_env env,
2965
+ napi_value* result) {
2966
+ // NAPI_PREAMBLE is not used here: this function must execute when there is a
2967
+ // pending exception.
2968
+ CHECK_ENV(env);
2969
+ CHECK_ARG(env, result);
2970
+
2971
+ if (env->last_exception.IsEmpty()) {
2972
+ return napi_get_undefined(env, result);
2973
+ } else {
2974
+ *result = v8impl::JsValueFromV8LocalValue(
2975
+ v8::Local<v8::Value>::New(env->isolate, env->last_exception));
2976
+ env->last_exception.Reset();
2977
+ }
2978
+
2979
+ return napi_clear_last_error(env);
2980
+ }
2981
+
2982
+ napi_status napi_create_buffer(napi_env env,
2983
+ size_t length,
2984
+ void** data,
2985
+ napi_value* result) {
2986
+ NAPI_PREAMBLE(env);
2987
+ CHECK_ARG(env, result);
2988
+
2989
+ auto maybe = node::Buffer::New(env->isolate, length);
2990
+
2991
+ CHECK_MAYBE_EMPTY(env, maybe, napi_generic_failure);
2992
+
2993
+ v8::Local<v8::Object> buffer = maybe.ToLocalChecked();
2994
+
2995
+ *result = v8impl::JsValueFromV8LocalValue(buffer);
2996
+
2997
+ if (data != nullptr) {
2998
+ *data = node::Buffer::Data(buffer);
2999
+ }
3000
+
3001
+ return GET_RETURN_STATUS(env);
3002
+ }
3003
+
3004
+ napi_status napi_create_external_buffer(napi_env env,
3005
+ size_t length,
3006
+ void* data,
3007
+ napi_finalize finalize_cb,
3008
+ void* finalize_hint,
3009
+ napi_value* result) {
3010
+ NAPI_PREAMBLE(env);
3011
+ CHECK_ARG(env, result);
3012
+
3013
+ v8::Isolate* isolate = env->isolate;
3014
+
3015
+ // The finalizer object will delete itself after invoking the callback.
3016
+ v8impl::Finalizer* finalizer = v8impl::Finalizer::New(
3017
+ env, finalize_cb, nullptr, finalize_hint);
3018
+
3019
+ auto maybe = node::Buffer::New(isolate,
3020
+ static_cast<char*>(data),
3021
+ length,
3022
+ v8impl::Finalizer::FinalizeBufferCallback,
3023
+ finalizer);
3024
+
3025
+ CHECK_MAYBE_EMPTY(env, maybe, napi_generic_failure);
3026
+
3027
+ *result = v8impl::JsValueFromV8LocalValue(maybe.ToLocalChecked());
3028
+ return GET_RETURN_STATUS(env);
3029
+ // Tell coverity that 'finalizer' should not be freed when we return
3030
+ // as it will be deleted when the buffer to which it is associated
3031
+ // is finalized.
3032
+ // coverity[leaked_storage]
3033
+ }
3034
+
3035
+ napi_status napi_create_buffer_copy(napi_env env,
3036
+ size_t length,
3037
+ const void* data,
3038
+ void** result_data,
3039
+ napi_value* result) {
3040
+ NAPI_PREAMBLE(env);
3041
+ CHECK_ARG(env, result);
3042
+
3043
+ auto maybe = node::Buffer::Copy(env->isolate,
3044
+ static_cast<const char*>(data), length);
3045
+
3046
+ CHECK_MAYBE_EMPTY(env, maybe, napi_generic_failure);
3047
+
3048
+ v8::Local<v8::Object> buffer = maybe.ToLocalChecked();
3049
+ *result = v8impl::JsValueFromV8LocalValue(buffer);
3050
+
3051
+ if (result_data != nullptr) {
3052
+ *result_data = node::Buffer::Data(buffer);
3053
+ }
3054
+
3055
+ return GET_RETURN_STATUS(env);
3056
+ }
3057
+
3058
+ napi_status napi_is_buffer(napi_env env, napi_value value, bool* result) {
3059
+ CHECK_ENV(env);
3060
+ CHECK_ARG(env, value);
3061
+ CHECK_ARG(env, result);
3062
+
3063
+ *result = node::Buffer::HasInstance(v8impl::V8LocalValueFromJsValue(value));
3064
+ return napi_clear_last_error(env);
3065
+ }
3066
+
3067
+ napi_status napi_get_buffer_info(napi_env env,
3068
+ napi_value value,
3069
+ void** data,
3070
+ size_t* length) {
3071
+ CHECK_ENV(env);
3072
+ CHECK_ARG(env, value);
3073
+
3074
+ v8::Local<v8::Value> buffer = v8impl::V8LocalValueFromJsValue(value);
3075
+
3076
+ if (data != nullptr) {
3077
+ *data = node::Buffer::Data(buffer);
3078
+ }
3079
+ if (length != nullptr) {
3080
+ *length = node::Buffer::Length(buffer);
3081
+ }
3082
+
3083
+ return napi_clear_last_error(env);
3084
+ }
3085
+
3086
+ napi_status napi_is_arraybuffer(napi_env env, napi_value value, bool* result) {
3087
+ CHECK_ENV(env);
3088
+ CHECK_ARG(env, value);
3089
+ CHECK_ARG(env, result);
3090
+
3091
+ v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
3092
+ *result = val->IsArrayBuffer();
3093
+
3094
+ return napi_clear_last_error(env);
3095
+ }
3096
+
3097
+ napi_status napi_create_arraybuffer(napi_env env,
3098
+ size_t byte_length,
3099
+ void** data,
3100
+ napi_value* result) {
3101
+ NAPI_PREAMBLE(env);
3102
+ CHECK_ARG(env, result);
3103
+
3104
+ v8::Isolate* isolate = env->isolate;
3105
+ v8::Local<v8::ArrayBuffer> buffer =
3106
+ v8::ArrayBuffer::New(isolate, byte_length);
3107
+
3108
+ // Optionally return a pointer to the buffer's data, to avoid another call to
3109
+ // retrieve it.
3110
+ if (data != nullptr) {
3111
+ *data = buffer->GetContents().Data();
3112
+ }
3113
+
3114
+ *result = v8impl::JsValueFromV8LocalValue(buffer);
3115
+ return GET_RETURN_STATUS(env);
3116
+ }
3117
+
3118
+ napi_status napi_create_external_arraybuffer(napi_env env,
3119
+ void* external_data,
3120
+ size_t byte_length,
3121
+ napi_finalize finalize_cb,
3122
+ void* finalize_hint,
3123
+ napi_value* result) {
3124
+ NAPI_PREAMBLE(env);
3125
+ CHECK_ARG(env, result);
3126
+
3127
+ v8::Isolate* isolate = env->isolate;
3128
+ v8::Local<v8::ArrayBuffer> buffer =
3129
+ v8::ArrayBuffer::New(isolate, external_data, byte_length);
3130
+
3131
+ if (finalize_cb != nullptr) {
3132
+ // Create a self-deleting weak reference that invokes the finalizer
3133
+ // callback.
3134
+ v8impl::Reference::New(env,
3135
+ buffer,
3136
+ 0,
3137
+ true,
3138
+ finalize_cb,
3139
+ external_data,
3140
+ finalize_hint);
3141
+ }
3142
+
3143
+ *result = v8impl::JsValueFromV8LocalValue(buffer);
3144
+ return GET_RETURN_STATUS(env);
3145
+ }
3146
+
3147
+ napi_status napi_get_arraybuffer_info(napi_env env,
3148
+ napi_value arraybuffer,
3149
+ void** data,
3150
+ size_t* byte_length) {
3151
+ CHECK_ENV(env);
3152
+ CHECK_ARG(env, arraybuffer);
3153
+
3154
+ v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(arraybuffer);
3155
+ RETURN_STATUS_IF_FALSE(env, value->IsArrayBuffer(), napi_invalid_arg);
3156
+
3157
+ v8::ArrayBuffer::Contents contents =
3158
+ value.As<v8::ArrayBuffer>()->GetContents();
3159
+
3160
+ if (data != nullptr) {
3161
+ *data = contents.Data();
3162
+ }
3163
+
3164
+ if (byte_length != nullptr) {
3165
+ *byte_length = contents.ByteLength();
3166
+ }
3167
+
3168
+ return napi_clear_last_error(env);
3169
+ }
3170
+
3171
+ napi_status napi_is_typedarray(napi_env env, napi_value value, bool* result) {
3172
+ CHECK_ENV(env);
3173
+ CHECK_ARG(env, value);
3174
+ CHECK_ARG(env, result);
3175
+
3176
+ v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
3177
+ *result = val->IsTypedArray();
3178
+
3179
+ return napi_clear_last_error(env);
3180
+ }
3181
+
3182
+ napi_status napi_create_typedarray(napi_env env,
3183
+ napi_typedarray_type type,
3184
+ size_t length,
3185
+ napi_value arraybuffer,
3186
+ size_t byte_offset,
3187
+ napi_value* result) {
3188
+ NAPI_PREAMBLE(env);
3189
+ CHECK_ARG(env, arraybuffer);
3190
+ CHECK_ARG(env, result);
3191
+
3192
+ v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(arraybuffer);
3193
+ RETURN_STATUS_IF_FALSE(env, value->IsArrayBuffer(), napi_invalid_arg);
3194
+
3195
+ v8::Local<v8::ArrayBuffer> buffer = value.As<v8::ArrayBuffer>();
3196
+ v8::Local<v8::TypedArray> typedArray;
3197
+
3198
+ switch (type) {
3199
+ case napi_int8_array:
3200
+ CREATE_TYPED_ARRAY(
3201
+ env, Int8Array, 1, buffer, byte_offset, length, typedArray);
3202
+ break;
3203
+ case napi_uint8_array:
3204
+ CREATE_TYPED_ARRAY(
3205
+ env, Uint8Array, 1, buffer, byte_offset, length, typedArray);
3206
+ break;
3207
+ case napi_uint8_clamped_array:
3208
+ CREATE_TYPED_ARRAY(
3209
+ env, Uint8ClampedArray, 1, buffer, byte_offset, length, typedArray);
3210
+ break;
3211
+ case napi_int16_array:
3212
+ CREATE_TYPED_ARRAY(
3213
+ env, Int16Array, 2, buffer, byte_offset, length, typedArray);
3214
+ break;
3215
+ case napi_uint16_array:
3216
+ CREATE_TYPED_ARRAY(
3217
+ env, Uint16Array, 2, buffer, byte_offset, length, typedArray);
3218
+ break;
3219
+ case napi_int32_array:
3220
+ CREATE_TYPED_ARRAY(
3221
+ env, Int32Array, 4, buffer, byte_offset, length, typedArray);
3222
+ break;
3223
+ case napi_uint32_array:
3224
+ CREATE_TYPED_ARRAY(
3225
+ env, Uint32Array, 4, buffer, byte_offset, length, typedArray);
3226
+ break;
3227
+ case napi_float32_array:
3228
+ CREATE_TYPED_ARRAY(
3229
+ env, Float32Array, 4, buffer, byte_offset, length, typedArray);
3230
+ break;
3231
+ case napi_float64_array:
3232
+ CREATE_TYPED_ARRAY(
3233
+ env, Float64Array, 8, buffer, byte_offset, length, typedArray);
3234
+ break;
3235
+ default:
3236
+ return napi_set_last_error(env, napi_invalid_arg);
3237
+ }
3238
+
3239
+ *result = v8impl::JsValueFromV8LocalValue(typedArray);
3240
+ return GET_RETURN_STATUS(env);
3241
+ }
3242
+
3243
+ napi_status napi_get_typedarray_info(napi_env env,
3244
+ napi_value typedarray,
3245
+ napi_typedarray_type* type,
3246
+ size_t* length,
3247
+ void** data,
3248
+ napi_value* arraybuffer,
3249
+ size_t* byte_offset) {
3250
+ CHECK_ENV(env);
3251
+ CHECK_ARG(env, typedarray);
3252
+
3253
+ v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(typedarray);
3254
+ RETURN_STATUS_IF_FALSE(env, value->IsTypedArray(), napi_invalid_arg);
3255
+
3256
+ v8::Local<v8::TypedArray> array = value.As<v8::TypedArray>();
3257
+
3258
+ if (type != nullptr) {
3259
+ if (value->IsInt8Array()) {
3260
+ *type = napi_int8_array;
3261
+ } else if (value->IsUint8Array()) {
3262
+ *type = napi_uint8_array;
3263
+ } else if (value->IsUint8ClampedArray()) {
3264
+ *type = napi_uint8_clamped_array;
3265
+ } else if (value->IsInt16Array()) {
3266
+ *type = napi_int16_array;
3267
+ } else if (value->IsUint16Array()) {
3268
+ *type = napi_uint16_array;
3269
+ } else if (value->IsInt32Array()) {
3270
+ *type = napi_int32_array;
3271
+ } else if (value->IsUint32Array()) {
3272
+ *type = napi_uint32_array;
3273
+ } else if (value->IsFloat32Array()) {
3274
+ *type = napi_float32_array;
3275
+ } else if (value->IsFloat64Array()) {
3276
+ *type = napi_float64_array;
3277
+ }
3278
+ }
3279
+
3280
+ if (length != nullptr) {
3281
+ *length = array->Length();
3282
+ }
3283
+
3284
+ v8::Local<v8::ArrayBuffer> buffer = array->Buffer();
3285
+ if (data != nullptr) {
3286
+ *data = static_cast<uint8_t*>(buffer->GetContents().Data()) +
3287
+ array->ByteOffset();
3288
+ }
3289
+
3290
+ if (arraybuffer != nullptr) {
3291
+ *arraybuffer = v8impl::JsValueFromV8LocalValue(buffer);
3292
+ }
3293
+
3294
+ if (byte_offset != nullptr) {
3295
+ *byte_offset = array->ByteOffset();
3296
+ }
3297
+
3298
+ return napi_clear_last_error(env);
3299
+ }
3300
+
3301
+ napi_status napi_create_dataview(napi_env env,
3302
+ size_t byte_length,
3303
+ napi_value arraybuffer,
3304
+ size_t byte_offset,
3305
+ napi_value* result) {
3306
+ NAPI_PREAMBLE(env);
3307
+ CHECK_ARG(env, arraybuffer);
3308
+ CHECK_ARG(env, result);
3309
+
3310
+ v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(arraybuffer);
3311
+ RETURN_STATUS_IF_FALSE(env, value->IsArrayBuffer(), napi_invalid_arg);
3312
+
3313
+ v8::Local<v8::ArrayBuffer> buffer = value.As<v8::ArrayBuffer>();
3314
+ if (byte_length + byte_offset > buffer->ByteLength()) {
3315
+ napi_throw_range_error(
3316
+ env,
3317
+ "ERR_NAPI_INVALID_DATAVIEW_ARGS",
3318
+ "byte_offset + byte_length should be less than or "
3319
+ "equal to the size in bytes of the array passed in");
3320
+ return napi_set_last_error(env, napi_generic_failure);
3321
+ }
3322
+ v8::Local<v8::DataView> DataView = v8::DataView::New(buffer, byte_offset,
3323
+ byte_length);
3324
+
3325
+ *result = v8impl::JsValueFromV8LocalValue(DataView);
3326
+ return GET_RETURN_STATUS(env);
3327
+ }
3328
+
3329
+ napi_status napi_is_dataview(napi_env env, napi_value value, bool* result) {
3330
+ CHECK_ENV(env);
3331
+ CHECK_ARG(env, value);
3332
+ CHECK_ARG(env, result);
3333
+
3334
+ v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
3335
+ *result = val->IsDataView();
3336
+
3337
+ return napi_clear_last_error(env);
3338
+ }
3339
+
3340
+ napi_status napi_get_dataview_info(napi_env env,
3341
+ napi_value dataview,
3342
+ size_t* byte_length,
3343
+ void** data,
3344
+ napi_value* arraybuffer,
3345
+ size_t* byte_offset) {
3346
+ CHECK_ENV(env);
3347
+ CHECK_ARG(env, dataview);
3348
+
3349
+ v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(dataview);
3350
+ RETURN_STATUS_IF_FALSE(env, value->IsDataView(), napi_invalid_arg);
3351
+
3352
+ v8::Local<v8::DataView> array = value.As<v8::DataView>();
3353
+
3354
+ if (byte_length != nullptr) {
3355
+ *byte_length = array->ByteLength();
3356
+ }
3357
+
3358
+ v8::Local<v8::ArrayBuffer> buffer = array->Buffer();
3359
+ if (data != nullptr) {
3360
+ *data = static_cast<uint8_t*>(buffer->GetContents().Data()) +
3361
+ array->ByteOffset();
3362
+ }
3363
+
3364
+ if (arraybuffer != nullptr) {
3365
+ *arraybuffer = v8impl::JsValueFromV8LocalValue(buffer);
3366
+ }
3367
+
3368
+ if (byte_offset != nullptr) {
3369
+ *byte_offset = array->ByteOffset();
3370
+ }
3371
+
3372
+ return napi_clear_last_error(env);
3373
+ }
3374
+
3375
+ napi_status napi_get_version(napi_env env, uint32_t* result) {
3376
+ CHECK_ENV(env);
3377
+ CHECK_ARG(env, result);
3378
+ *result = NAPI_VERSION;
3379
+ return napi_clear_last_error(env);
3380
+ }
3381
+
3382
+ napi_status napi_get_node_version(napi_env env,
3383
+ const napi_node_version** result) {
3384
+ CHECK_ENV(env);
3385
+ CHECK_ARG(env, result);
3386
+ static const napi_node_version version = {
3387
+ NODE_MAJOR_VERSION,
3388
+ NODE_MINOR_VERSION,
3389
+ NODE_PATCH_VERSION,
3390
+ NODE_RELEASE
3391
+ };
3392
+ *result = &version;
3393
+ return napi_clear_last_error(env);
3394
+ }
3395
+
3396
+ napi_status napi_adjust_external_memory(napi_env env,
3397
+ int64_t change_in_bytes,
3398
+ int64_t* adjusted_value) {
3399
+ CHECK_ENV(env);
3400
+ CHECK_ARG(env, adjusted_value);
3401
+
3402
+ *adjusted_value = env->isolate->AdjustAmountOfExternalAllocatedMemory(
3403
+ change_in_bytes);
3404
+
3405
+ return napi_clear_last_error(env);
3406
+ }
3407
+
3408
+ namespace {
3409
+ namespace uvimpl {
3410
+
3411
+ static napi_status ConvertUVErrorCode(int code) {
3412
+ switch (code) {
3413
+ case 0:
3414
+ return napi_ok;
3415
+ case UV_EINVAL:
3416
+ return napi_invalid_arg;
3417
+ case UV_ECANCELED:
3418
+ return napi_cancelled;
3419
+ }
3420
+
3421
+ return napi_generic_failure;
3422
+ }
3423
+
3424
+ // Wrapper around uv_work_t which calls user-provided callbacks.
3425
+ class Work : public node::AsyncResource {
3426
+ private:
3427
+ explicit Work(napi_env env,
3428
+ v8::Local<v8::Object> async_resource,
3429
+ v8::Local<v8::String> async_resource_name,
3430
+ napi_async_execute_callback execute,
3431
+ napi_async_complete_callback complete = nullptr,
3432
+ void* data = nullptr)
3433
+ : AsyncResource(env->isolate,
3434
+ async_resource,
3435
+ *v8::String::Utf8Value(async_resource_name)),
3436
+ _env(env),
3437
+ _data(data),
3438
+ _execute(execute),
3439
+ _complete(complete) {
3440
+ memset(&_request, 0, sizeof(_request));
3441
+ _request.data = this;
3442
+ }
3443
+
3444
+ ~Work() { }
3445
+
3446
+ public:
3447
+ static Work* New(napi_env env,
3448
+ v8::Local<v8::Object> async_resource,
3449
+ v8::Local<v8::String> async_resource_name,
3450
+ napi_async_execute_callback execute,
3451
+ napi_async_complete_callback complete,
3452
+ void* data) {
3453
+ return new Work(env, async_resource, async_resource_name,
3454
+ execute, complete, data);
3455
+ }
3456
+
3457
+ static void Delete(Work* work) {
3458
+ delete work;
3459
+ }
3460
+
3461
+ static void ExecuteCallback(uv_work_t* req) {
3462
+ Work* work = static_cast<Work*>(req->data);
3463
+ work->_execute(work->_env, work->_data);
3464
+ }
3465
+
3466
+ static void CompleteCallback(uv_work_t* req, int status) {
3467
+ Work* work = static_cast<Work*>(req->data);
3468
+
3469
+ if (work->_complete != nullptr) {
3470
+ napi_env env = work->_env;
3471
+
3472
+ // Establish a handle scope here so that every callback doesn't have to.
3473
+ // Also it is needed for the exception-handling below.
3474
+ v8::HandleScope scope(env->isolate);
3475
+ CallbackScope callback_scope(work);
3476
+
3477
+ NAPI_CALL_INTO_MODULE(env,
3478
+ work->_complete(env, ConvertUVErrorCode(status), work->_data),
3479
+ [env] (v8::Local<v8::Value> local_err) {
3480
+ // If there was an unhandled exception in the complete callback,
3481
+ // report it as a fatal exception. (There is no JavaScript on the
3482
+ // callstack that can possibly handle it.)
3483
+ v8impl::trigger_fatal_exception(env, local_err);
3484
+ });
3485
+
3486
+ // Note: Don't access `work` after this point because it was
3487
+ // likely deleted by the complete callback.
3488
+ }
3489
+ }
3490
+
3491
+ uv_work_t* Request() {
3492
+ return &_request;
3493
+ }
3494
+
3495
+ private:
3496
+ napi_env _env;
3497
+ void* _data;
3498
+ uv_work_t _request;
3499
+ napi_async_execute_callback _execute;
3500
+ napi_async_complete_callback _complete;
3501
+ };
3502
+
3503
+ } // end of namespace uvimpl
3504
+ } // end of anonymous namespace
3505
+
3506
+ #define CALL_UV(env, condition) \
3507
+ do { \
3508
+ int result = (condition); \
3509
+ napi_status status = uvimpl::ConvertUVErrorCode(result); \
3510
+ if (status != napi_ok) { \
3511
+ return napi_set_last_error(env, status, result); \
3512
+ } \
3513
+ } while (0)
3514
+
3515
+ napi_status napi_create_async_work(napi_env env,
3516
+ napi_value async_resource,
3517
+ napi_value async_resource_name,
3518
+ napi_async_execute_callback execute,
3519
+ napi_async_complete_callback complete,
3520
+ void* data,
3521
+ napi_async_work* result) {
3522
+ CHECK_ENV(env);
3523
+ CHECK_ARG(env, execute);
3524
+ CHECK_ARG(env, result);
3525
+
3526
+ v8::Local<v8::Context> context = env->isolate->GetCurrentContext();
3527
+
3528
+ v8::Local<v8::Object> resource;
3529
+ if (async_resource != nullptr) {
3530
+ CHECK_TO_OBJECT(env, context, resource, async_resource);
3531
+ } else {
3532
+ resource = v8::Object::New(env->isolate);
3533
+ }
3534
+
3535
+ v8::Local<v8::String> resource_name;
3536
+ CHECK_TO_STRING(env, context, resource_name, async_resource_name);
3537
+
3538
+ uvimpl::Work* work =
3539
+ uvimpl::Work::New(env, resource, resource_name,
3540
+ execute, complete, data);
3541
+
3542
+ *result = reinterpret_cast<napi_async_work>(work);
3543
+
3544
+ return napi_clear_last_error(env);
3545
+ }
3546
+
3547
+ napi_status napi_delete_async_work(napi_env env, napi_async_work work) {
3548
+ CHECK_ENV(env);
3549
+ CHECK_ARG(env, work);
3550
+
3551
+ uvimpl::Work::Delete(reinterpret_cast<uvimpl::Work*>(work));
3552
+
3553
+ return napi_clear_last_error(env);
3554
+ }
3555
+
3556
+ napi_status napi_queue_async_work(napi_env env, napi_async_work work) {
3557
+ CHECK_ENV(env);
3558
+ CHECK_ARG(env, work);
3559
+
3560
+ // Consider: Encapsulate the uv_loop_t into an opaque pointer parameter.
3561
+ // Currently the environment event loop is the same as the UV default loop.
3562
+ // Someday (if node ever supports multiple isolates), it may be better to get
3563
+ // the loop from node::Environment::GetCurrent(env->isolate)->event_loop();
3564
+ uv_loop_t* event_loop = uv_default_loop();
3565
+
3566
+ uvimpl::Work* w = reinterpret_cast<uvimpl::Work*>(work);
3567
+
3568
+ CALL_UV(env, uv_queue_work(event_loop,
3569
+ w->Request(),
3570
+ uvimpl::Work::ExecuteCallback,
3571
+ uvimpl::Work::CompleteCallback));
3572
+
3573
+ return napi_clear_last_error(env);
3574
+ }
3575
+
3576
+ napi_status napi_cancel_async_work(napi_env env, napi_async_work work) {
3577
+ CHECK_ENV(env);
3578
+ CHECK_ARG(env, work);
3579
+
3580
+ uvimpl::Work* w = reinterpret_cast<uvimpl::Work*>(work);
3581
+
3582
+ CALL_UV(env, uv_cancel(reinterpret_cast<uv_req_t*>(w->Request())));
3583
+
3584
+ return napi_clear_last_error(env);
3585
+ }
3586
+
3587
+ napi_status napi_create_promise(napi_env env,
3588
+ napi_deferred* deferred,
3589
+ napi_value* promise) {
3590
+ NAPI_PREAMBLE(env);
3591
+ CHECK_ARG(env, deferred);
3592
+ CHECK_ARG(env, promise);
3593
+
3594
+ auto maybe = v8::Promise::Resolver::New(env->isolate->GetCurrentContext());
3595
+ CHECK_MAYBE_EMPTY(env, maybe, napi_generic_failure);
3596
+
3597
+ auto v8_resolver = maybe.ToLocalChecked();
3598
+ auto v8_deferred = new v8::Persistent<v8::Value>();
3599
+ v8_deferred->Reset(env->isolate, v8_resolver);
3600
+
3601
+ *deferred = v8impl::JsDeferredFromV8Persistent(v8_deferred);
3602
+ *promise = v8impl::JsValueFromV8LocalValue(v8_resolver->GetPromise());
3603
+ return GET_RETURN_STATUS(env);
3604
+ }
3605
+
3606
+ napi_status napi_resolve_deferred(napi_env env,
3607
+ napi_deferred deferred,
3608
+ napi_value resolution) {
3609
+ return v8impl::ConcludeDeferred(env, deferred, resolution, true);
3610
+ }
3611
+
3612
+ napi_status napi_reject_deferred(napi_env env,
3613
+ napi_deferred deferred,
3614
+ napi_value resolution) {
3615
+ return v8impl::ConcludeDeferred(env, deferred, resolution, false);
3616
+ }
3617
+
3618
+ napi_status napi_is_promise(napi_env env,
3619
+ napi_value promise,
3620
+ bool* is_promise) {
3621
+ CHECK_ENV(env);
3622
+ CHECK_ARG(env, promise);
3623
+ CHECK_ARG(env, is_promise);
3624
+
3625
+ *is_promise = v8impl::V8LocalValueFromJsValue(promise)->IsPromise();
3626
+
3627
+ return napi_clear_last_error(env);
3628
+ }
3629
+
3630
+ napi_status napi_run_script(napi_env env,
3631
+ napi_value script,
3632
+ napi_value* result) {
3633
+ NAPI_PREAMBLE(env);
3634
+ CHECK_ARG(env, script);
3635
+ CHECK_ARG(env, result);
3636
+
3637
+ v8::Local<v8::Value> v8_script = v8impl::V8LocalValueFromJsValue(script);
3638
+
3639
+ if (!v8_script->IsString()) {
3640
+ return napi_set_last_error(env, napi_string_expected);
3641
+ }
3642
+
3643
+ v8::Local<v8::Context> context = env->isolate->GetCurrentContext();
3644
+
3645
+ auto maybe_script = v8::Script::Compile(context,
3646
+ v8::Local<v8::String>::Cast(v8_script));
3647
+ CHECK_MAYBE_EMPTY(env, maybe_script, napi_generic_failure);
3648
+
3649
+ auto script_result =
3650
+ maybe_script.ToLocalChecked()->Run(context);
3651
+ CHECK_MAYBE_EMPTY(env, script_result, napi_generic_failure);
3652
+
3653
+ *result = v8impl::JsValueFromV8LocalValue(script_result.ToLocalChecked());
3654
+ return GET_RETURN_STATUS(env);
3655
+ }