@scriptc/cli-darwin-arm64 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (260) hide show
  1. package/dist/THIRD_PARTY_NOTICES +1 -1
  2. package/dist/bin/scriptc +0 -0
  3. package/dist/bin/scriptc.json +1 -1
  4. package/dist/lib/declarations/scriptc-node-fallback.d.ts +84 -19
  5. package/dist/lib/llvm/bin/scriptc-llvm-codegen +0 -0
  6. package/dist/lib/llvm/package.json +1 -1
  7. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_array.o +0 -0
  8. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_assert.o +0 -0
  9. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_async.o +0 -0
  10. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_async_dyn.o +0 -0
  11. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_bigint.o +0 -0
  12. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_bytes.o +0 -0
  13. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_bytes_io.o +0 -0
  14. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_child.o +0 -0
  15. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_console.o +0 -0
  16. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_console_native.o +0 -0
  17. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_crypto_async.o +0 -0
  18. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_dyn_invoke.o +0 -0
  19. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_error.o +0 -0
  20. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_events.o +0 -0
  21. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_exception.o +0 -0
  22. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_fetch.o +0 -0
  23. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_file_handle.o +0 -0
  24. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_grapheme.o +0 -0
  25. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_http.o +0 -0
  26. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_http2.o +0 -0
  27. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_json.o +0 -0
  28. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_lib.o +0 -0
  29. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_map.o +0 -0
  30. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_net.o +0 -0
  31. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_node_builtin.o +0 -0
  32. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_object.o +0 -0
  33. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_qs.o +0 -0
  34. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_regex.o +0 -0
  35. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_stream.o +0 -0
  36. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_string.o +0 -0
  37. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_symbol.o +0 -0
  38. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_url.o +0 -0
  39. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_array.o +0 -0
  40. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_assert.o +0 -0
  41. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_async.o +0 -0
  42. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_async_dyn.o +0 -0
  43. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_bigint.o +0 -0
  44. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_bytes.o +0 -0
  45. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_bytes_io.o +0 -0
  46. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_child.o +0 -0
  47. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_console.o +0 -0
  48. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_console_native.o +0 -0
  49. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_crypto_async.o +0 -0
  50. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_dyn_invoke.o +0 -0
  51. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_error.o +0 -0
  52. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_events.o +0 -0
  53. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_exception.o +0 -0
  54. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_file_handle.o +0 -0
  55. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_grapheme.o +0 -0
  56. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_http.o +0 -0
  57. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_http2.o +0 -0
  58. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_island.o +0 -0
  59. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_json.o +0 -0
  60. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_lib.o +0 -0
  61. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_map.o +0 -0
  62. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_net.o +0 -0
  63. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_node_builtin.o +0 -0
  64. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_object.o +0 -0
  65. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_qs.o +0 -0
  66. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_regex.o +0 -0
  67. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_stream.o +0 -0
  68. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_string.o +0 -0
  69. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_symbol.o +0 -0
  70. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_url.o +0 -0
  71. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_web.o +0 -0
  72. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic-text-decoder-legacy/scr_bytes.o +0 -0
  73. package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
  74. package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_array.o +0 -0
  75. package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_assert.o +0 -0
  76. package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_bigint.o +0 -0
  77. package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_bytes.o +0 -0
  78. package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_bytes_io.o +0 -0
  79. package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_console_native.o +0 -0
  80. package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_dyn_invoke.o +0 -0
  81. package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_error.o +0 -0
  82. package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_exception.o +0 -0
  83. package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_grapheme.o +0 -0
  84. package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_json.o +0 -0
  85. package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_lib.o +0 -0
  86. package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_map.o +0 -0
  87. package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_node_builtin.o +0 -0
  88. package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_object.o +0 -0
  89. package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_regex.o +0 -0
  90. package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_string.o +0 -0
  91. package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_symbol.o +0 -0
  92. package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_url.o +0 -0
  93. package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
  94. package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_array.o +0 -0
  95. package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_assert.o +0 -0
  96. package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_bigint.o +0 -0
  97. package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_bytes.o +0 -0
  98. package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_bytes_io.o +0 -0
  99. package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_console_native.o +0 -0
  100. package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_dyn_invoke.o +0 -0
  101. package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_error.o +0 -0
  102. package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_exception.o +0 -0
  103. package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_grapheme.o +0 -0
  104. package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_json.o +0 -0
  105. package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_lib.o +0 -0
  106. package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_map.o +0 -0
  107. package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_node_builtin.o +0 -0
  108. package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_object.o +0 -0
  109. package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_regex.o +0 -0
  110. package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_string.o +0 -0
  111. package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_symbol.o +0 -0
  112. package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_url.o +0 -0
  113. package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
  114. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_array.o +0 -0
  115. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_assert.o +0 -0
  116. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_bigint.o +0 -0
  117. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_bytes.o +0 -0
  118. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_bytes_io.o +0 -0
  119. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_console_native.o +0 -0
  120. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_dyn_invoke.o +0 -0
  121. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_error.o +0 -0
  122. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_exception.o +0 -0
  123. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_grapheme.o +0 -0
  124. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_json.o +0 -0
  125. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_lib.o +0 -0
  126. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_map.o +0 -0
  127. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_node_builtin.o +0 -0
  128. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_object.o +0 -0
  129. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_regex.o +0 -0
  130. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_string.o +0 -0
  131. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_symbol.o +0 -0
  132. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_url.o +0 -0
  133. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
  134. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_array.o +0 -0
  135. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_assert.o +0 -0
  136. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_bigint.o +0 -0
  137. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_bytes.o +0 -0
  138. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_bytes_io.o +0 -0
  139. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_console_native.o +0 -0
  140. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_dyn_invoke.o +0 -0
  141. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_error.o +0 -0
  142. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_exception.o +0 -0
  143. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_grapheme.o +0 -0
  144. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_json.o +0 -0
  145. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_lib.o +0 -0
  146. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_map.o +0 -0
  147. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_node_builtin.o +0 -0
  148. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_object.o +0 -0
  149. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_regex.o +0 -0
  150. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_string.o +0 -0
  151. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_symbol.o +0 -0
  152. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_url.o +0 -0
  153. package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
  154. package/dist/lib/runtime-darwin-arm64/artifacts/licenses/v8-number-radix.txt +61 -0
  155. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_array.o +0 -0
  156. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_assert.o +0 -0
  157. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_async.o +0 -0
  158. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_async_dyn.o +0 -0
  159. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_bigint.o +0 -0
  160. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_bytes.o +0 -0
  161. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_bytes_io.o +0 -0
  162. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_child.o +0 -0
  163. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_console.o +0 -0
  164. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_console_native.o +0 -0
  165. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_crypto_async.o +0 -0
  166. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_dyn_invoke.o +0 -0
  167. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_error.o +0 -0
  168. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_events.o +0 -0
  169. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_exception.o +0 -0
  170. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_fetch.o +0 -0
  171. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_file_handle.o +0 -0
  172. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_grapheme.o +0 -0
  173. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_http.o +0 -0
  174. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_http2.o +0 -0
  175. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_json.o +0 -0
  176. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_lib.o +0 -0
  177. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_map.o +0 -0
  178. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_net.o +0 -0
  179. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_node_builtin.o +0 -0
  180. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_object.o +0 -0
  181. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_qs.o +0 -0
  182. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_regex.o +0 -0
  183. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_stream.o +0 -0
  184. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_string.o +0 -0
  185. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_symbol.o +0 -0
  186. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_url.o +0 -0
  187. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_array.o +0 -0
  188. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_assert.o +0 -0
  189. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_async.o +0 -0
  190. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_async_dyn.o +0 -0
  191. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_bigint.o +0 -0
  192. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_bytes.o +0 -0
  193. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_bytes_io.o +0 -0
  194. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_child.o +0 -0
  195. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_console.o +0 -0
  196. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_console_native.o +0 -0
  197. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_crypto_async.o +0 -0
  198. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_dyn_invoke.o +0 -0
  199. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_error.o +0 -0
  200. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_events.o +0 -0
  201. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_exception.o +0 -0
  202. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_file_handle.o +0 -0
  203. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_grapheme.o +0 -0
  204. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_http.o +0 -0
  205. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_http2.o +0 -0
  206. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_island.o +0 -0
  207. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_json.o +0 -0
  208. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_lib.o +0 -0
  209. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_map.o +0 -0
  210. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_net.o +0 -0
  211. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_node_builtin.o +0 -0
  212. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_object.o +0 -0
  213. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_qs.o +0 -0
  214. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_regex.o +0 -0
  215. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_stream.o +0 -0
  216. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_string.o +0 -0
  217. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_symbol.o +0 -0
  218. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_url.o +0 -0
  219. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_web.o +0 -0
  220. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic-text-decoder-legacy/scr_bytes.o +0 -0
  221. package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
  222. package/dist/lib/runtime-darwin-arm64/package.json +1 -1
  223. package/dist/lib/runtime-darwin-arm64/runtime-pack.json +549 -545
  224. package/dist/lib/runtime-sources/package.json +1 -1
  225. package/dist/lib/runtime-sources/src/scr_abort.c +5 -0
  226. package/dist/lib/runtime-sources/src/scr_array.c +16 -0
  227. package/dist/lib/runtime-sources/src/scr_assert.c +1 -0
  228. package/dist/lib/runtime-sources/src/scr_async.c +38 -5
  229. package/dist/lib/runtime-sources/src/scr_async_dyn.c +208 -40
  230. package/dist/lib/runtime-sources/src/scr_bigint.c +8 -0
  231. package/dist/lib/runtime-sources/src/scr_bytes.c +431 -41
  232. package/dist/lib/runtime-sources/src/scr_bytes_io.c +628 -12
  233. package/dist/lib/runtime-sources/src/scr_child.c +544 -17
  234. package/dist/lib/runtime-sources/src/scr_console.c +1 -1
  235. package/dist/lib/runtime-sources/src/scr_crypto_async.c +22 -2
  236. package/dist/lib/runtime-sources/src/scr_dyn_invoke.c +344 -73
  237. package/dist/lib/runtime-sources/src/scr_error.c +52 -5
  238. package/dist/lib/runtime-sources/src/scr_exception.c +21 -5
  239. package/dist/lib/runtime-sources/src/scr_fetch.c +311 -3
  240. package/dist/lib/runtime-sources/src/scr_file_handle.c +31 -0
  241. package/dist/lib/runtime-sources/src/scr_http.c +3 -0
  242. package/dist/lib/runtime-sources/src/scr_island.c +1226 -405
  243. package/dist/lib/runtime-sources/src/scr_island_manifest.h +11 -9
  244. package/dist/lib/runtime-sources/src/scr_json.c +1594 -139
  245. package/dist/lib/runtime-sources/src/scr_json.test.ts +1 -0
  246. package/dist/lib/runtime-sources/src/scr_lib.c +816 -34
  247. package/dist/lib/runtime-sources/src/scr_map.c +47 -0
  248. package/dist/lib/runtime-sources/src/scr_node_builtin.c +10 -0
  249. package/dist/lib/runtime-sources/src/scr_object.c +11 -0
  250. package/dist/lib/runtime-sources/src/scr_qs.c +10 -0
  251. package/dist/lib/runtime-sources/src/scr_regex.c +148 -72
  252. package/dist/lib/runtime-sources/src/scr_runtime.h +257 -41
  253. package/dist/lib/runtime-sources/src/scr_stream.c +197 -0
  254. package/dist/lib/runtime-sources/src/scr_string.c +16 -1
  255. package/dist/lib/runtime-sources/src/scr_symbol.c +5 -0
  256. package/dist/lib/runtime-sources/src/scr_text_decoder_labels.h +225 -0
  257. package/dist/lib/runtime-sources/src/scr_url.c +206 -10
  258. package/dist/lib/runtime-sources/src/scr_web.c +129 -26
  259. package/dist/lib/runtime-sources/vendor/v8-number-radix/LICENSE +61 -0
  260. package/package.json +1 -1
@@ -7,6 +7,7 @@
7
7
  * encoding conversions (utf8 with WHATWG replacement, hex, base64) match
8
8
  * Node byte-for-byte — the differential corpus holds them to it. */
9
9
  #include "scr_runtime.h"
10
+ #include "scr_text_decoder_labels.h"
10
11
  #ifdef SCR_TEXT_DECODER_LEGACY
11
12
  #include "scr_text_decoder_data.h"
12
13
  #endif
@@ -16,6 +17,61 @@
16
17
  #include <stdlib.h>
17
18
  #include <string.h>
18
19
 
20
+ static bool scr_td_label_space(unsigned char c) {
21
+ return c == 9 || c == 10 || c == 12 || c == 13 || c == 32;
22
+ }
23
+
24
+ double scr_text_decoder_encoding(const ScrDyn *label) {
25
+ if (!label || label->kind == SCR_DYN_UNDEF) return -1;
26
+ ScrStr *text = scr_dyn_string_coerce_js(label);
27
+ if (!text) return -1;
28
+ size_t start = 0, end = text->len;
29
+ while (start < end && scr_td_label_space((unsigned char)text->data[start])) start++;
30
+ while (end > start && scr_td_label_space((unsigned char)text->data[end - 1])) end--;
31
+ for (size_t i = 0; i < sizeof scr_td_labels / sizeof scr_td_labels[0]; i++) {
32
+ const char *candidate = scr_td_labels[i].label;
33
+ if (strlen(candidate) != end - start) continue;
34
+ bool matches = true;
35
+ for (size_t j = start; j < end; j++) {
36
+ unsigned char c = (unsigned char)text->data[j];
37
+ if (c >= 'A' && c <= 'Z') c += 'a' - 'A';
38
+ if (c != (unsigned char)candidate[j - start]) { matches = false; break; }
39
+ }
40
+ if (matches) {
41
+ double result = scr_td_labels[i].encoding;
42
+ scr_str_release(text);
43
+ return result;
44
+ }
45
+ }
46
+ static const char prefix[] = "The \"";
47
+ static const char suffix[] = "\" encoding is not supported";
48
+ size_t length = sizeof prefix - 1 + text->len + sizeof suffix - 1;
49
+ char *message = malloc(length + 1);
50
+ if (!message) scr_trap("scriptc: out of memory\n");
51
+ memcpy(message, prefix, sizeof prefix - 1);
52
+ memcpy(message + sizeof prefix - 1, text->data, text->len);
53
+ memcpy(message + sizeof prefix - 1 + text->len, suffix, sizeof suffix);
54
+ scr_throw_error_msg_code(SCR_ERR_RANGE, message, length, "ERR_ENCODING_NOT_SUPPORTED");
55
+ free(message);
56
+ scr_str_release(text);
57
+ return -1;
58
+ }
59
+
60
+ ScrStr *scr_text_decoder_name(double encoding) {
61
+ static const char *names[] = {
62
+ "ibm866", "iso-8859-2", "iso-8859-3", "iso-8859-4", "iso-8859-5",
63
+ "iso-8859-6", "iso-8859-7", "iso-8859-8", "iso-8859-10", "iso-8859-13",
64
+ "iso-8859-14", "iso-8859-15", "iso-8859-16", "koi8-r", "koi8-u",
65
+ "macintosh", "windows-874", "windows-1250", "windows-1251", "windows-1252",
66
+ "windows-1253", "windows-1254", "windows-1255", "windows-1256", "windows-1257",
67
+ "windows-1258", "x-mac-cyrillic", "x-user-defined", "utf-16le", "utf-16be",
68
+ "gb18030", "big5", "euc-jp", "iso-2022-jp", "shift_jis", "euc-kr",
69
+ "iso-8859-8-i", "gbk",
70
+ };
71
+ const char *name = encoding < 0 ? "utf-8" : names[(unsigned)encoding];
72
+ return scr_str_new(name, strlen(name));
73
+ }
74
+
19
75
  #ifdef SCR_RC_AUDIT
20
76
  static SCR_TL long scr_live_bytes = 0;
21
77
  long scr_bytes_live_count(void) { return scr_live_bytes; }
@@ -70,6 +126,7 @@ static ScrBytes *scr_bytes_alloc(ScrBytesElem elem, size_t len) {
70
126
  if (!b->data) scr_bytes_oom();
71
127
  b->backing = NULL;
72
128
  b->is_buffer = false;
129
+ b->is_data_view = false;
73
130
  b->external = false;
74
131
  #ifdef SCR_RC_AUDIT
75
132
  scr_live_bytes++;
@@ -129,6 +186,7 @@ ScrBytes *scr_bytes_raw_view(ScrBytes *bytes) {
129
186
 
130
187
  ScrBytes *scr_bytes_as_buffer(ScrBytes *bytes) {
131
188
  bytes->is_buffer = true;
189
+ bytes->is_data_view = false;
132
190
  return scr_bytes_retain(bytes);
133
191
  }
134
192
 
@@ -172,9 +230,8 @@ double scr_bytes_byte_len(const ScrBytes *b) {
172
230
  }
173
231
 
174
232
  /* ── element access ────────────────────────────────────────────────────
175
- * JS reads undefined and IGNORES writes out of bounds on typed arrays;
176
- * both are unrepresentable here, so any invalid index traps — the array
177
- * runtime's exact discipline (SEMANTICS.md). */
233
+ * Invalid writes are ignored. Typed numeric reads cannot represent
234
+ * undefined, so invalid reads trap; checked reads return undefined. */
178
235
 
179
236
  static size_t scr_bytes_check_index(const ScrBytes *b, double i) {
180
237
  if (!(i >= 0) || i != trunc(i) || i >= (double)b->len) {
@@ -241,7 +298,8 @@ double scr_bytes_get(const ScrBytes *b, double i) {
241
298
  }
242
299
 
243
300
  void scr_bytes_set(ScrBytes *b, double i, double v) {
244
- size_t idx = scr_bytes_check_index(b, i);
301
+ if (!(i >= 0) || i != trunc(i) || i >= (double)b->len) return;
302
+ size_t idx = (size_t)i;
245
303
  switch (b->elem) {
246
304
  case SCR_BYTES_U8: case SCR_BYTES_I8:
247
305
  b->data[idx] = (uint8_t)scr_bytes_to_u32(v);
@@ -341,6 +399,7 @@ ScrBytes *scr_bytes_subarray(ScrBytes *b, double start, double end) {
341
399
  v->data = b->data + s * scr_bytes_elem_size(b->elem);
342
400
  v->backing = scr_bytes_retain(owner);
343
401
  v->is_buffer = b->is_buffer;
402
+ v->is_data_view = false;
344
403
  v->external = false;
345
404
  #ifdef SCR_RC_AUDIT
346
405
  scr_live_bytes++;
@@ -554,6 +613,7 @@ ScrBytes *scr_dataview_new(ScrBytes *src, double byte_off, bool has_len, double
554
613
  v->data = owner->data + (size_t)off;
555
614
  v->backing = scr_bytes_retain(owner);
556
615
  v->is_buffer = false;
616
+ v->is_data_view = true;
557
617
  v->external = false;
558
618
  #ifdef SCR_RC_AUDIT
559
619
  scr_live_bytes++;
@@ -581,6 +641,7 @@ ScrBytes *scr_bytes_buffer_view(ScrBytes *src, ScrBytesElem elem,
581
641
  if (!view) return NULL;
582
642
  view->elem = elem;
583
643
  view->len /= width;
644
+ view->is_data_view = false;
584
645
  return view;
585
646
  }
586
647
 
@@ -699,7 +760,13 @@ static const char scr_hex_digits[] = "0123456789abcdef";
699
760
  /* WHATWG UTF-8 decode with U+FFFD replacement per maximal invalid subpart
700
761
  * — what Buffer.prototype.toString("utf8") does. Output re-encodes as
701
762
  * (now valid) UTF-8: worst case 3 bytes per input byte. */
702
- static ScrStr *scr_bytes_decode_utf8(const uint8_t *in, size_t n) {
763
+ static void scr_td_invalid(const char *encoding) {
764
+ char message[160];
765
+ int n = snprintf(message, sizeof message, "The encoded data was not valid for encoding %s", encoding);
766
+ scr_throw_error_msg_code(SCR_ERR_TYPE, message, (size_t)n, "ERR_ENCODING_INVALID_ENCODED_DATA");
767
+ }
768
+
769
+ static ScrStr *scr_bytes_decode_utf8_options(const uint8_t *in, size_t n, bool fatal) {
703
770
  if (in == NULL && n != 0) {
704
771
  scr_trap("scriptc: native callback passed a NULL span with nonzero length\n");
705
772
  }
@@ -713,6 +780,7 @@ static ScrStr *scr_bytes_decode_utf8(const uint8_t *in, size_t n) {
713
780
  for (size_t i = 0; i <= n; i++) {
714
781
  if (i == n) {
715
782
  if (needed > 0) { /* EOF inside a sequence: one replacement */
783
+ if (fatal) { free(out); scr_td_invalid("utf-8"); return NULL; }
716
784
  memcpy(out + o, "\xef\xbf\xbd", 3);
717
785
  o += 3;
718
786
  }
@@ -733,6 +801,7 @@ static ScrStr *scr_bytes_decode_utf8(const uint8_t *in, size_t n) {
733
801
  if (byte == 0xf4) upper = 0x8f;
734
802
  needed = 3; cp = byte & 0x7;
735
803
  } else {
804
+ if (fatal) { free(out); scr_td_invalid("utf-8"); return NULL; }
736
805
  memcpy(out + o, "\xef\xbf\xbd", 3);
737
806
  o += 3;
738
807
  }
@@ -740,6 +809,7 @@ static ScrStr *scr_bytes_decode_utf8(const uint8_t *in, size_t n) {
740
809
  }
741
810
  if (byte < lower || byte > upper) {
742
811
  /* Invalid continuation: replace the subpart, REPROCESS this byte. */
812
+ if (fatal) { free(out); scr_td_invalid("utf-8"); return NULL; }
743
813
  memcpy(out + o, "\xef\xbf\xbd", 3);
744
814
  o += 3;
745
815
  needed = 0; lower = 0x80; upper = 0xbf;
@@ -772,6 +842,10 @@ static ScrStr *scr_bytes_decode_utf8(const uint8_t *in, size_t n) {
772
842
  return s;
773
843
  }
774
844
 
845
+ static ScrStr *scr_bytes_decode_utf8(const uint8_t *in, size_t n) {
846
+ return scr_bytes_decode_utf8_options(in, n, false);
847
+ }
848
+
775
849
  ScrStr *scr_str_from_utf8_lossy(const uint8_t *bytes, size_t len) {
776
850
  return scr_bytes_decode_utf8(bytes, len);
777
851
  }
@@ -780,14 +854,47 @@ ScrStr *scr_str_from_utf8_lossy(const uint8_t *bytes, size_t len) {
780
854
  * subpart replacement decode as toString("utf8") above, with one
781
855
  * difference — a leading UTF-8 BOM is stripped (ignoreBOM defaults to
782
856
  * false in the spec; Buffer.toString keeps the BOM as U+FEFF). */
783
- ScrStr *scr_text_decode(const ScrBytes *b) {
857
+ ScrStr *scr_text_decode_options(const ScrBytes *b, bool fatal, bool ignore_bom) {
784
858
  const uint8_t *in = b->data;
785
859
  size_t n = b->len;
786
- if (n >= 3 && in[0] == 0xef && in[1] == 0xbb && in[2] == 0xbf) {
860
+ if (!ignore_bom && n >= 3 && in[0] == 0xef && in[1] == 0xbb && in[2] == 0xbf) {
787
861
  in += 3;
788
862
  n -= 3;
789
863
  }
790
- return scr_bytes_decode_utf8(in, n);
864
+ return scr_bytes_decode_utf8_options(in, n, fatal);
865
+ }
866
+
867
+ ScrBytes *scr_bytes_buffer_source(const ScrDyn *value) {
868
+ if (value->kind == SCR_DYN_TYPED_REF) {
869
+ ScrDyn *materialized = scr_dyn_typed_ref_materialize(value);
870
+ if (!materialized) return NULL;
871
+ ScrBytes *result = scr_bytes_buffer_source(materialized);
872
+ scr_dyn_release(materialized);
873
+ return result;
874
+ }
875
+ if (value->kind == SCR_DYN_UNDEF) return scr_bytes_new(SCR_BYTES_U8, 0);
876
+ if (value->kind == SCR_DYN_BYTES) {
877
+ ScrBytes *bytes = value->v.bytes;
878
+ return scr_bytes_buffer_view(bytes, SCR_BYTES_U8, scr_bytes_byte_offset(bytes), true, scr_bytes_byte_len(bytes));
879
+ }
880
+ if (scr_array_buffer_is(value)) {
881
+ return scr_array_buffer_view(SCR_BYTES_U8, value, scr_dyn_undefined(), scr_dyn_undefined());
882
+ }
883
+ static const char message[] = "The input argument must be an instance of SharedArrayBuffer, ArrayBuffer or ArrayBufferView.";
884
+ scr_throw_error_msg_code(SCR_ERR_TYPE, message, sizeof message - 1, "ERR_INVALID_ARG_TYPE");
885
+ return NULL;
886
+ }
887
+
888
+ ScrStr *scr_text_decode_buffer_source(const ScrDyn *value) {
889
+ ScrBytes *view = scr_bytes_buffer_source(value);
890
+ if (!view) return NULL;
891
+ ScrStr *out = scr_text_decode(view);
892
+ scr_bytes_release(view);
893
+ return out;
894
+ }
895
+
896
+ ScrStr *scr_text_decode(const ScrBytes *b) {
897
+ return scr_text_decode_options(b, false, false);
791
898
  }
792
899
 
793
900
  /* ── node:string_decoder, the utf8 StringDecoder ─────────────────────────
@@ -1067,11 +1174,12 @@ enum {
1067
1174
  typedef struct {
1068
1175
  char *data;
1069
1176
  size_t len;
1177
+ bool failed;
1070
1178
  } ScrTdOut;
1071
1179
 
1072
1180
  static ScrTdOut scr_td_out_new(size_t input_len) {
1073
1181
  if (input_len > (SIZE_MAX - 8) / 3) scr_bytes_oom();
1074
- ScrTdOut out = { malloc(input_len * 3 + 8), 0 };
1182
+ ScrTdOut out = { malloc(input_len * 3 + 8), 0, false };
1075
1183
  if (!out.data) scr_bytes_oom();
1076
1184
  return out;
1077
1185
  }
@@ -1081,39 +1189,42 @@ static void scr_td_put(ScrTdOut *out, uint32_t cp) {
1081
1189
  }
1082
1190
 
1083
1191
  static void scr_td_error(ScrTdOut *out) {
1192
+ out->failed = true;
1084
1193
  scr_td_put(out, 0xfffd);
1085
1194
  }
1086
1195
 
1087
- static ScrStr *scr_td_finish(ScrTdOut *out) {
1196
+ static ScrStr *scr_td_finish(ScrTdOut *out, bool fatal) {
1197
+ if (fatal && out->failed) { free(out->data); scr_td_invalid("legacy encoding"); return NULL; }
1088
1198
  ScrStr *str = scr_str_new(out->data, out->len);
1089
1199
  free(out->data);
1090
1200
  return str;
1091
1201
  }
1092
1202
 
1093
- static ScrStr *scr_td_single_byte(const ScrBytes *b, unsigned encoding) {
1203
+ static ScrStr *scr_td_single_byte(const ScrBytes *b, unsigned encoding, bool fatal) {
1094
1204
  ScrTdOut out = scr_td_out_new(b->len);
1095
1205
  for (size_t i = 0; i < b->len; i++) {
1096
1206
  uint8_t byte = b->data[i];
1097
- scr_td_put(&out, byte < 0x80 ? byte : scr_td_single[encoding][byte - 0x80]);
1207
+ uint32_t cp = byte < 0x80 ? byte : scr_td_single[encoding][byte - 0x80];
1208
+ if (cp == 0xfffd) scr_td_error(&out); else scr_td_put(&out, cp);
1098
1209
  }
1099
- return scr_td_finish(&out);
1210
+ return scr_td_finish(&out, fatal);
1100
1211
  }
1101
1212
 
1102
- static ScrStr *scr_td_x_user_defined(const ScrBytes *b) {
1213
+ static ScrStr *scr_td_x_user_defined(const ScrBytes *b, bool fatal) {
1103
1214
  ScrTdOut out = scr_td_out_new(b->len);
1104
1215
  for (size_t i = 0; i < b->len; i++) {
1105
1216
  uint8_t byte = b->data[i];
1106
1217
  scr_td_put(&out, byte < 0x80 ? byte : 0xf780 + byte - 0x80);
1107
1218
  }
1108
- return scr_td_finish(&out);
1219
+ return scr_td_finish(&out, fatal);
1109
1220
  }
1110
1221
 
1111
- static ScrStr *scr_td_utf16(const ScrBytes *b, bool be) {
1222
+ static ScrStr *scr_td_utf16(const ScrBytes *b, bool be, bool fatal, bool ignore_bom) {
1112
1223
  const uint8_t *in = b->data;
1113
1224
  size_t n = b->len;
1114
1225
  /* TextDecoder's BOM handling strips only the BOM matching the selected
1115
1226
  * endian decoder. The opposite BOM decodes to U+FFFE and remains. */
1116
- if (n >= 2 && ((!be && in[0] == 0xff && in[1] == 0xfe) ||
1227
+ if (!ignore_bom && n >= 2 && ((!be && in[0] == 0xff && in[1] == 0xfe) ||
1117
1228
  (be && in[0] == 0xfe && in[1] == 0xff))) {
1118
1229
  in += 2;
1119
1230
  n -= 2;
@@ -1146,7 +1257,7 @@ static ScrStr *scr_td_utf16(const ScrBytes *b, bool be) {
1146
1257
  else scr_td_put(&out, cu);
1147
1258
  }
1148
1259
  if (i < n) scr_td_error(&out); /* odd trailing byte */
1149
- return scr_td_finish(&out);
1260
+ return scr_td_finish(&out, fatal);
1150
1261
  }
1151
1262
 
1152
1263
  static uint32_t scr_td_gb_range(uint32_t pointer) {
@@ -1165,7 +1276,7 @@ static uint32_t scr_td_gb_range(uint32_t pointer) {
1165
1276
  /* A tiny prepend stack models the Encoding Standard's I/O queue restore.
1166
1277
  * The gb18030 decoder is the only legacy decoder which can restore three
1167
1278
  * bytes after discovering a malformed four-byte sequence. */
1168
- static ScrStr *scr_td_gb18030_decode(const ScrBytes *b) {
1279
+ static ScrStr *scr_td_gb18030_decode(const ScrBytes *b, bool fatal) {
1169
1280
  ScrTdOut out = scr_td_out_new(b->len);
1170
1281
  uint8_t first = 0, second = 0, third = 0;
1171
1282
  uint8_t replay[3];
@@ -1238,10 +1349,10 @@ static ScrStr *scr_td_gb18030_decode(const ScrBytes *b) {
1238
1349
  else scr_td_error(&out);
1239
1350
  }
1240
1351
  if (first || second || third) scr_td_error(&out);
1241
- return scr_td_finish(&out);
1352
+ return scr_td_finish(&out, fatal);
1242
1353
  }
1243
1354
 
1244
- static ScrStr *scr_td_big5_decode(const ScrBytes *b) {
1355
+ static ScrStr *scr_td_big5_decode(const ScrBytes *b, bool fatal) {
1245
1356
  ScrTdOut out = scr_td_out_new(b->len);
1246
1357
  uint8_t lead = 0;
1247
1358
  for (size_t i = 0; i < b->len; i++) {
@@ -1267,10 +1378,10 @@ static ScrStr *scr_td_big5_decode(const ScrBytes *b) {
1267
1378
  else scr_td_error(&out);
1268
1379
  }
1269
1380
  if (lead) scr_td_error(&out);
1270
- return scr_td_finish(&out);
1381
+ return scr_td_finish(&out, fatal);
1271
1382
  }
1272
1383
 
1273
- static ScrStr *scr_td_euc_jp_decode(const ScrBytes *b) {
1384
+ static ScrStr *scr_td_euc_jp_decode(const ScrBytes *b, bool fatal) {
1274
1385
  ScrTdOut out = scr_td_out_new(b->len);
1275
1386
  uint8_t lead = 0;
1276
1387
  bool jis0212 = false;
@@ -1330,10 +1441,10 @@ static ScrStr *scr_td_euc_jp_decode(const ScrBytes *b) {
1330
1441
  else scr_td_error(&out);
1331
1442
  }
1332
1443
  if (lead) scr_td_error(&out);
1333
- return scr_td_finish(&out);
1444
+ return scr_td_finish(&out, fatal);
1334
1445
  }
1335
1446
 
1336
- static ScrStr *scr_td_shift_jis_decode(const ScrBytes *b) {
1447
+ static ScrStr *scr_td_shift_jis_decode(const ScrBytes *b, bool fatal) {
1337
1448
  ScrTdOut out = scr_td_out_new(b->len);
1338
1449
  uint8_t lead = 0;
1339
1450
  for (size_t i = 0; i < b->len; i++) {
@@ -1367,10 +1478,10 @@ static ScrStr *scr_td_shift_jis_decode(const ScrBytes *b) {
1367
1478
  else scr_td_error(&out);
1368
1479
  }
1369
1480
  if (lead) scr_td_error(&out);
1370
- return scr_td_finish(&out);
1481
+ return scr_td_finish(&out, fatal);
1371
1482
  }
1372
1483
 
1373
- static ScrStr *scr_td_euc_kr_decode(const ScrBytes *b) {
1484
+ static ScrStr *scr_td_euc_kr_decode(const ScrBytes *b, bool fatal) {
1374
1485
  ScrTdOut out = scr_td_out_new(b->len);
1375
1486
  uint8_t lead = 0;
1376
1487
  for (size_t i = 0; i < b->len; i++) {
@@ -1393,7 +1504,7 @@ static ScrStr *scr_td_euc_kr_decode(const ScrBytes *b) {
1393
1504
  else scr_td_error(&out);
1394
1505
  }
1395
1506
  if (lead) scr_td_error(&out);
1396
- return scr_td_finish(&out);
1507
+ return scr_td_finish(&out, fatal);
1397
1508
  }
1398
1509
 
1399
1510
  enum ScrTdIsoState {
@@ -1406,7 +1517,7 @@ enum ScrTdIsoState {
1406
1517
  SCR_TD_ISO_ESCAPE,
1407
1518
  };
1408
1519
 
1409
- static ScrStr *scr_td_iso_2022_jp_decode(const ScrBytes *b) {
1520
+ static ScrStr *scr_td_iso_2022_jp_decode(const ScrBytes *b, bool fatal) {
1410
1521
  ScrTdOut out = scr_td_out_new(b->len);
1411
1522
  enum ScrTdIsoState state = SCR_TD_ISO_ASCII;
1412
1523
  enum ScrTdIsoState output_state = SCR_TD_ISO_ASCII;
@@ -1574,27 +1685,98 @@ static ScrStr *scr_td_iso_2022_jp_decode(const ScrBytes *b) {
1574
1685
  }
1575
1686
  }
1576
1687
  }
1577
- return scr_td_finish(&out);
1688
+ return scr_td_finish(&out, fatal);
1578
1689
  }
1579
1690
 
1580
- ScrStr *scr_text_decode_legacy(const ScrBytes *b, double encoding_value) {
1691
+ ScrStr *scr_text_decode_legacy_options(const ScrBytes *b, double encoding_value, bool fatal, bool ignore_bom) {
1581
1692
  unsigned encoding = (unsigned)encoding_value;
1582
- if (encoding < SCR_TD_SINGLE_COUNT) return scr_td_single_byte(b, encoding);
1693
+ if (encoding == 36) encoding = 7; /* ISO-8859-8-I */
1694
+ if (encoding == 37) encoding = SCR_TD_GB18030; /* GBK */
1695
+ if (encoding < SCR_TD_SINGLE_COUNT) return scr_td_single_byte(b, encoding, fatal);
1583
1696
  switch (encoding) {
1584
- case SCR_TD_X_USER_DEFINED: return scr_td_x_user_defined(b);
1585
- case SCR_TD_UTF16LE: return scr_td_utf16(b, false);
1586
- case SCR_TD_UTF16BE: return scr_td_utf16(b, true);
1587
- case SCR_TD_GB18030: return scr_td_gb18030_decode(b);
1588
- case SCR_TD_BIG5: return scr_td_big5_decode(b);
1589
- case SCR_TD_EUC_JP: return scr_td_euc_jp_decode(b);
1590
- case SCR_TD_ISO_2022_JP: return scr_td_iso_2022_jp_decode(b);
1591
- case SCR_TD_SHIFT_JIS: return scr_td_shift_jis_decode(b);
1592
- case SCR_TD_EUC_KR: return scr_td_euc_kr_decode(b);
1697
+ case SCR_TD_X_USER_DEFINED: return scr_td_x_user_defined(b, fatal);
1698
+ case SCR_TD_UTF16LE: return scr_td_utf16(b, false, fatal, ignore_bom);
1699
+ case SCR_TD_UTF16BE: return scr_td_utf16(b, true, fatal, ignore_bom);
1700
+ case SCR_TD_GB18030: return scr_td_gb18030_decode(b, fatal);
1701
+ case SCR_TD_BIG5: return scr_td_big5_decode(b, fatal);
1702
+ case SCR_TD_EUC_JP: return scr_td_euc_jp_decode(b, fatal);
1703
+ case SCR_TD_ISO_2022_JP: return scr_td_iso_2022_jp_decode(b, fatal);
1704
+ case SCR_TD_SHIFT_JIS: return scr_td_shift_jis_decode(b, fatal);
1705
+ case SCR_TD_EUC_KR: return scr_td_euc_kr_decode(b, fatal);
1593
1706
  default: return scr_str_new("", 0); /* compiler invariant */
1594
1707
  }
1595
1708
  }
1709
+ ScrStr *scr_text_decode_legacy(const ScrBytes *b, double encoding_value) {
1710
+ return scr_text_decode_legacy_options(b, encoding_value, false, false);
1711
+ }
1596
1712
  #endif /* SCR_TEXT_DECODER_LEGACY */
1597
1713
 
1714
+ /* Streaming decoders retain only an incomplete character and whether the
1715
+ * initial BOM has been handled. The state object belongs to the codec's
1716
+ * private record, so aliases and closure captures share the same decoder. */
1717
+ static size_t scr_td_utf8_tail(const uint8_t *bytes, size_t n) {
1718
+ size_t tail = scr_strdec_tail(bytes, n);
1719
+ if (!tail) return 0;
1720
+ uint8_t lead = bytes[n - tail];
1721
+ if (lead < 0xc2 || lead > 0xf4) return 0;
1722
+ if (tail > 1) {
1723
+ uint8_t second = bytes[n - tail + 1];
1724
+ if ((lead == 0xe0 && second < 0xa0) || (lead == 0xed && second > 0x9f) ||
1725
+ (lead == 0xf0 && second < 0x90) || (lead == 0xf4 && second > 0x8f)) return 0;
1726
+ }
1727
+ return tail;
1728
+ }
1729
+
1730
+ ScrStr *scr_text_decode_stream(ScrDyn *state, const ScrBytes *input,
1731
+ double encoding, bool fatal, bool ignore_bom, bool stream) {
1732
+ if (encoding == 36) encoding = 7; /* ISO-8859-8-I is a single-byte decoder. */
1733
+ ScrDyn *saved = scr_dyn_obj_read(state, "pending", 7);
1734
+ size_t pending = saved->kind == SCR_DYN_BYTES ? saved->v.bytes->len : 0;
1735
+ if (input->len > SIZE_MAX - pending) scr_bytes_oom();
1736
+ ScrBytes *combined = scr_bytes_new(SCR_BYTES_U8, (double)(pending + input->len));
1737
+ if (pending) memcpy(combined->data, saved->v.bytes->data, pending);
1738
+ if (input->len) memcpy(combined->data + pending, input->data, input->len);
1739
+ scr_dyn_release(saved);
1740
+ ScrDyn *bom = scr_dyn_obj_read(state, "bom", 3);
1741
+ bool seen_bom = scr_dyn_truthy(bom);
1742
+ scr_dyn_release(bom);
1743
+ size_t hold = stream && encoding < 0 ? scr_td_utf8_tail(combined->data, combined->len) : 0;
1744
+ #ifdef SCR_TEXT_DECODER_LEGACY
1745
+ if (stream && ((unsigned)encoding == SCR_TD_UTF16LE || (unsigned)encoding == SCR_TD_UTF16BE)) {
1746
+ size_t complete = combined->len & ~(size_t)1;
1747
+ hold = combined->len - complete;
1748
+ if (complete >= 2) {
1749
+ const uint8_t *last = combined->data + complete - 2;
1750
+ uint16_t unit = (unsigned)encoding == SCR_TD_UTF16BE
1751
+ ? ((uint16_t)last[0] << 8) | last[1] : last[0] | ((uint16_t)last[1] << 8);
1752
+ if (unit >= 0xd800 && unit <= 0xdbff) hold += 2;
1753
+ }
1754
+ }
1755
+ if (stream && encoding >= SCR_TD_GB18030) {
1756
+ scr_bytes_release(combined);
1757
+ static const char message[] = "Streaming TextDecoder for this legacy encoding has no native lowering";
1758
+ scr_throw_error_msg_code(SCR_ERR_ERROR, message, sizeof message - 1, "SC2020");
1759
+ return NULL;
1760
+ }
1761
+ #endif
1762
+ size_t complete = combined->len - hold;
1763
+ ScrBytes *tail = scr_bytes_new(SCR_BYTES_U8, (double)hold);
1764
+ if (hold) memcpy(tail->data, combined->data + complete, hold);
1765
+ scr_dyn_obj_set(state, "pending", 7, scr_dyn_new_bytes(tail));
1766
+ scr_bytes_release(tail);
1767
+ scr_dyn_obj_set(state, "bom", 3, scr_dyn_new_bool(stream && (seen_bom || complete > 0)));
1768
+ combined->len = complete;
1769
+ ScrStr *result;
1770
+ if (encoding < 0) result = scr_text_decode_options(combined, fatal, ignore_bom || seen_bom);
1771
+ #ifdef SCR_TEXT_DECODER_LEGACY
1772
+ else result = scr_text_decode_legacy_options(combined, encoding, fatal, ignore_bom || seen_bom);
1773
+ #else
1774
+ else { result = NULL; scr_trap("legacy TextDecoder requires its runtime pack variant"); }
1775
+ #endif
1776
+ scr_bytes_release(combined);
1777
+ return result;
1778
+ }
1779
+
1598
1780
  /* Decode the next code point from an ScrStr's storage — ALWAYS valid
1599
1781
  * UTF-8 (the string runtime never stores ill-formed sequences), so no
1600
1782
  * validation re-runs here. */
@@ -1621,6 +1803,214 @@ static uint32_t scr_bytes_next_cp(const uint8_t *in, size_t *ip) {
1621
1803
  return cp;
1622
1804
  }
1623
1805
 
1806
+ /* encodeInto consumes complete Unicode scalars while counting UTF-16 units.
1807
+ * Borrow the destination so writes through a subarray retain their aliasing. */
1808
+ ScrDyn *scr_text_encode_into(const ScrDyn *source, const ScrDyn *destination) {
1809
+ if (source->kind != SCR_DYN_STR) {
1810
+ scr_dyn_arg_type_fail("src", "of type string", source);
1811
+ return NULL;
1812
+ }
1813
+ if (destination->kind != SCR_DYN_BYTES || destination->v.bytes->elem != SCR_BYTES_U8 || destination->v.bytes->is_data_view) {
1814
+ scr_dyn_arg_type_fail("dest", "an instance of Uint8Array", destination);
1815
+ return NULL;
1816
+ }
1817
+ const ScrStr *text = source->v.str;
1818
+ ScrBytes *dest = destination->v.bytes;
1819
+ size_t read = 0, written = 0;
1820
+ while (written < text->len) {
1821
+ size_t end = written;
1822
+ uint32_t cp = scr_bytes_next_cp((const uint8_t *)text->data, &end);
1823
+ if (end > dest->len) break;
1824
+ read += cp > 0xffff ? 2 : 1;
1825
+ written = end;
1826
+ }
1827
+ if (written) memcpy(dest->data, text->data, written);
1828
+ ScrDyn *result = scr_dyn_new_obj();
1829
+ scr_dyn_obj_set(result, "read", 4, scr_dyn_new_num((double)read));
1830
+ scr_dyn_obj_set(result, "written", 7, scr_dyn_new_num((double)written));
1831
+ return result;
1832
+ }
1833
+
1834
+ static ScrBytes *scr_buffer_validation_input(const ScrDyn *input) {
1835
+ if ((input->kind == SCR_DYN_BYTES && !input->v.bytes->is_data_view) || scr_array_buffer_is(input)) {
1836
+ return scr_bytes_buffer_source(input);
1837
+ }
1838
+ scr_dyn_arg_type_fail("input", "an instance of ArrayBuffer, Buffer, or TypedArray", input);
1839
+ return NULL;
1840
+ }
1841
+
1842
+ static bool scr_buffer_utf8_valid(const uint8_t *data, size_t len) {
1843
+ size_t i = 0;
1844
+ while (i < len) {
1845
+ unsigned byte = data[i++], count;
1846
+ unsigned low = 0x80, high = 0xbf;
1847
+ if (byte < 0x80) continue;
1848
+ if (byte >= 0xc2 && byte <= 0xdf) count = 1;
1849
+ else if (byte >= 0xe0 && byte <= 0xef) {
1850
+ count = 2;
1851
+ if (byte == 0xe0) low = 0xa0;
1852
+ if (byte == 0xed) high = 0x9f;
1853
+ } else if (byte >= 0xf0 && byte <= 0xf4) {
1854
+ count = 3;
1855
+ if (byte == 0xf0) low = 0x90;
1856
+ if (byte == 0xf4) high = 0x8f;
1857
+ } else return false;
1858
+ if (count > len - i || data[i] < low || data[i] > high) return false;
1859
+ i++;
1860
+ for (unsigned j = 1; j < count; j++, i++) if (data[i] < 0x80 || data[i] > 0xbf) return false;
1861
+ }
1862
+ return true;
1863
+ }
1864
+
1865
+ bool scr_buffer_is_ascii(const ScrDyn *input) {
1866
+ ScrBytes *bytes = scr_buffer_validation_input(input);
1867
+ if (!bytes) return false;
1868
+ bool result = true;
1869
+ for (size_t i = 0; i < bytes->len; i++) if (bytes->data[i] > 0x7f) { result = false; break; }
1870
+ scr_bytes_release(bytes);
1871
+ return result;
1872
+ }
1873
+
1874
+ bool scr_buffer_is_utf8(const ScrDyn *input) {
1875
+ ScrBytes *bytes = scr_buffer_validation_input(input);
1876
+ if (!bytes) return false;
1877
+ bool result = scr_buffer_utf8_valid(bytes->data, bytes->len);
1878
+ scr_bytes_release(bytes);
1879
+ return result;
1880
+ }
1881
+
1882
+ /* Node's ICU wrapper recognizes Buffer encoding aliases. Empty inputs return
1883
+ * before resolving either encoding. The four actual converter families are
1884
+ * implemented here without adding an ICU dependency to a native binary. */
1885
+ enum { SCR_TC_UTF8, SCR_TC_ASCII, SCR_TC_LATIN1, SCR_TC_UTF16 };
1886
+
1887
+ static int scr_transcode_encoding(const ScrDyn *value) {
1888
+ if (value->kind == SCR_DYN_NULL || value->kind == SCR_DYN_UNDEF ||
1889
+ (value->kind == SCR_DYN_STR && value->v.str->len == 0)) return SCR_TC_UTF8;
1890
+ if (value->kind != SCR_DYN_STR) return -1;
1891
+ const ScrStr *name = value->v.str;
1892
+ static const struct { const char *name; int encoding; } aliases[] = {
1893
+ {"utf8", SCR_TC_UTF8}, {"utf-8", SCR_TC_UTF8}, {"ascii", SCR_TC_ASCII},
1894
+ {"latin1", SCR_TC_LATIN1}, {"binary", SCR_TC_LATIN1},
1895
+ {"utf16le", SCR_TC_UTF16}, {"utf-16le", SCR_TC_UTF16},
1896
+ {"ucs2", SCR_TC_UTF16}, {"ucs-2", SCR_TC_UTF16},
1897
+ };
1898
+ for (size_t i = 0; i < sizeof aliases / sizeof aliases[0]; i++) {
1899
+ if (strlen(aliases[i].name) != name->len) continue;
1900
+ bool match = true;
1901
+ for (size_t j = 0; j < name->len; j++) {
1902
+ unsigned char c = (unsigned char)name->data[j];
1903
+ if (c >= 'A' && c <= 'Z') c += 'a' - 'A';
1904
+ if (c != (unsigned char)aliases[i].name[j]) { match = false; break; }
1905
+ }
1906
+ if (match) return aliases[i].encoding;
1907
+ }
1908
+ return -1;
1909
+ }
1910
+
1911
+ static ScrBytes *scr_transcode_error(bool invalid_data) {
1912
+ const char *code = invalid_data ? "U_INVALID_CHAR_FOUND" : "U_ILLEGAL_ARGUMENT_ERROR";
1913
+ char message[100];
1914
+ int length = snprintf(message, sizeof message, "Unable to transcode Buffer [%s]", code);
1915
+ ScrStr *text = scr_str_new(message, (size_t)length);
1916
+ ScrError *error = scr_error_new(SCR_ERR_ERROR, text);
1917
+ scr_str_release(text);
1918
+ scr_error_set_code(error, code);
1919
+ scr_throw_obj(error, &scr_error_retain_v, &scr_error_release_v, scr_error_trace_arg());
1920
+ return NULL;
1921
+ }
1922
+
1923
+ /* ICU's pinned substitute callback skips unmappable default-ignorable code
1924
+ * points. Mappable Latin-1 characters (including soft hyphen) still survive. */
1925
+ static bool scr_transcode_ignorable(uint32_t cp) {
1926
+ return cp == 0xad || cp == 0x34f || cp == 0x61c || cp == 0x115f || cp == 0x1160 ||
1927
+ (cp >= 0x17b4 && cp <= 0x17b5) || (cp >= 0x180b && cp <= 0x180f) ||
1928
+ (cp >= 0x200b && cp <= 0x200f) || (cp >= 0x202a && cp <= 0x202e) ||
1929
+ (cp >= 0x2060 && cp <= 0x206f) || cp == 0x3164 ||
1930
+ (cp >= 0xfe00 && cp <= 0xfe0f) || cp == 0xfeff || cp == 0xffa0 ||
1931
+ (cp >= 0xfff0 && cp <= 0xfff8) || (cp >= 0x1bca0 && cp <= 0x1bca3) ||
1932
+ (cp >= 0x1d173 && cp <= 0x1d17a) || (cp >= 0xe0000 && cp <= 0xe0fff);
1933
+ }
1934
+
1935
+ static size_t scr_transcode_put(uint8_t *out, size_t index, uint32_t cp, int encoding) {
1936
+ if (encoding == SCR_TC_ASCII || encoding == SCR_TC_LATIN1) {
1937
+ unsigned limit = encoding == SCR_TC_ASCII ? 0x7f : 0xff;
1938
+ if (cp <= limit) out[index++] = (uint8_t)cp;
1939
+ else if (!scr_transcode_ignorable(cp)) out[index++] = '?';
1940
+ } else if (encoding == SCR_TC_UTF16) {
1941
+ if (cp > 0xffff) {
1942
+ uint32_t high = 0xd800 + ((cp - 0x10000) >> 10);
1943
+ out[index++] = (uint8_t)high;
1944
+ out[index++] = (uint8_t)(high >> 8);
1945
+ cp = 0xdc00 + ((cp - 0x10000) & 0x3ff);
1946
+ }
1947
+ out[index++] = (uint8_t)cp;
1948
+ out[index++] = (uint8_t)(cp >> 8);
1949
+ } else if (cp < 0x80) out[index++] = (uint8_t)cp;
1950
+ else if (cp < 0x800) {
1951
+ out[index++] = 0xc0 | (cp >> 6); out[index++] = 0x80 | (cp & 63);
1952
+ } else if (cp < 0x10000) {
1953
+ out[index++] = 0xe0 | (cp >> 12); out[index++] = 0x80 | ((cp >> 6) & 63); out[index++] = 0x80 | (cp & 63);
1954
+ } else {
1955
+ out[index++] = 0xf0 | (cp >> 18); out[index++] = 0x80 | ((cp >> 12) & 63);
1956
+ out[index++] = 0x80 | ((cp >> 6) & 63); out[index++] = 0x80 | (cp & 63);
1957
+ }
1958
+ return index;
1959
+ }
1960
+
1961
+ ScrBytes *scr_buffer_transcode(const ScrDyn *source, const ScrDyn *from, const ScrDyn *to) {
1962
+ if (source->kind != SCR_DYN_BYTES || source->v.bytes->elem != SCR_BYTES_U8 || source->v.bytes->is_data_view) {
1963
+ scr_dyn_arg_type_fail("source", "an instance of Buffer or Uint8Array", source);
1964
+ return NULL;
1965
+ }
1966
+ const ScrBytes *input = source->v.bytes;
1967
+ size_t len = input->len;
1968
+ if (!len) { ScrBytes *empty = scr_bytes_alloc(SCR_BYTES_U8, 0); empty->is_buffer = true; return empty; }
1969
+ int from_encoding = scr_transcode_encoding(from), to_encoding = scr_transcode_encoding(to);
1970
+ if (from_encoding < 0 || to_encoding < 0) return scr_transcode_error(false);
1971
+ if (len > (SIZE_MAX - 4) / 4) scr_bytes_oom();
1972
+ ScrBytes *result = scr_bytes_alloc(SCR_BYTES_U8, len * 4 + 4);
1973
+ result->is_buffer = true;
1974
+ size_t written = 0;
1975
+ if (from_encoding == SCR_TC_UTF8) {
1976
+ if (to_encoding == SCR_TC_UTF16 && !scr_buffer_utf8_valid(input->data, len)) {
1977
+ scr_bytes_release(result); return scr_transcode_error(true);
1978
+ }
1979
+ ScrStr *text = scr_str_from_utf8_lossy(input->data, len);
1980
+ for (size_t i = 0; i < text->len;) {
1981
+ uint32_t cp = scr_bytes_next_cp((const uint8_t *)text->data, &i);
1982
+ written = scr_transcode_put(result->data, written, cp, to_encoding);
1983
+ }
1984
+ scr_str_release(text);
1985
+ } else if (from_encoding == SCR_TC_UTF16) {
1986
+ size_t end = to_encoding == SCR_TC_UTF16 ? len : len & ~(size_t)1;
1987
+ if (to_encoding == SCR_TC_UTF8 && end == 0) { scr_bytes_release(result); return scr_transcode_error(true); }
1988
+ for (size_t i = 0; i < end;) {
1989
+ uint32_t cp = 0xfffd;
1990
+ bool invalid = false;
1991
+ if (i + 1 < end) {
1992
+ cp = input->data[i] | ((uint32_t)input->data[i + 1] << 8);
1993
+ i += 2;
1994
+ if (cp >= 0xd800 && cp <= 0xdbff) {
1995
+ uint32_t next = i + 1 < end ? input->data[i] | ((uint32_t)input->data[i + 1] << 8) : 0;
1996
+ if (next >= 0xdc00 && next <= 0xdfff) { cp = 0x10000 + ((cp - 0xd800) << 10) + next - 0xdc00; i += 2; }
1997
+ else { cp = 0xfffd; invalid = true; }
1998
+ } else if (cp >= 0xdc00 && cp <= 0xdfff) { cp = 0xfffd; invalid = true; }
1999
+ } else { i++; invalid = true; }
2000
+ if (invalid && to_encoding == SCR_TC_UTF8) { scr_bytes_release(result); return scr_transcode_error(true); }
2001
+ written = scr_transcode_put(result->data, written, cp, to_encoding);
2002
+ }
2003
+ } else {
2004
+ for (size_t i = 0; i < len; i++) {
2005
+ uint32_t cp = input->data[i];
2006
+ if (from_encoding == SCR_TC_ASCII && cp > 0x7f && to_encoding != SCR_TC_UTF16) cp = 0xfffd;
2007
+ written = scr_transcode_put(result->data, written, cp, to_encoding);
2008
+ }
2009
+ }
2010
+ result->len = written;
2011
+ return result;
2012
+ }
2013
+
1624
2014
  static bool scr_enc_is(const ScrStr *enc, const char *name) {
1625
2015
  size_t n = strlen(name);
1626
2016
  return enc->len == n && memcmp(enc->data, name, n) == 0;