elide-dev / elide

fast polyglot runtime
https://elide.dev
MIT License
100 stars 16 forks source link

feat(node): custom Buffer implementation #1072

Closed darvld closed 1 month ago

darvld commented 1 month ago

Draft Powered by Pull Request Badge

Summary

Adds a custom implementation of the Node.js Buffer class, for use both as a global symbol and as part of the node:buffer built-in module. Two new interfaces are added: BufferInstance represents actual Buffer objects, with BufferClass serving as meta-object, holding all static (class-level) properties and methods.

This means that when injected into a guest context, there should only be one instance of BufferClass, which is bound as the Buffer symbol (and inside node:buffer), which can in turn be used to create multiple BufferInstance objects using the Node.js API.

Pending changes

The following changes are vital to the feature and currently block merge:

sonarcloud[bot] commented 1 month ago

Quality Gate Passed Quality Gate passed

Issues
12 New issues
0 Accepted issues

Measures
0 Security Hotspots
60.5% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 51.26147% with 425 lines in your changes missing coverage. Please review.

Project coverage is 52.55%. Comparing base (84ec973) to head (40acda6).

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/elide-dev/elide/pull/1072/graphs/tree.svg?width=650&height=150&src=pr&token=FXxhJlpKG3&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev)](https://app.codecov.io/gh/elide-dev/elide/pull/1072?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev) ```diff @@ Coverage Diff @@ ## main #1072 +/- ## ========================================== - Coverage 53.17% 52.55% -0.62% ========================================== Files 405 413 +8 Lines 14207 15055 +848 Branches 2394 2720 +326 ========================================== + Hits 7554 7912 +358 - Misses 5903 6236 +333 - Partials 750 907 +157 ``` | [Flag](https://app.codecov.io/gh/elide-dev/elide/pull/1072/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev) | Coverage Δ | | |---|---|---| | [jvm](https://app.codecov.io/gh/elide-dev/elide/pull/1072/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev) | `52.55% <51.26%> (-0.62%)` | :arrow_down: | | [lib](https://app.codecov.io/gh/elide-dev/elide/pull/1072/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev) | `52.55% <51.26%> (-0.62%)` | :arrow_down: | | [native](https://app.codecov.io/gh/elide-dev/elide/pull/1072/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev) | `79.39% <ø> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/elide-dev/elide/pull/1072?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev) | Coverage Δ | | |---|---|---| | [...de/runtime/gvm/internals/node/buffer/NodeBuffer.kt](https://app.codecov.io/gh/elide-dev/elide/pull/1072?src=pr&el=tree&filepath=packages%2Fgraalvm%2Fsrc%2Fmain%2Fkotlin%2Felide%2Fruntime%2Fgvm%2Finternals%2Fnode%2Fbuffer%2FNodeBuffer.kt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev#diff-cGFja2FnZXMvZ3JhYWx2bS9zcmMvbWFpbi9rb3RsaW4vZWxpZGUvcnVudGltZS9ndm0vaW50ZXJuYWxzL25vZGUvYnVmZmVyL05vZGVCdWZmZXIua3Q=) | `47.69% <100.00%> (+0.81%)` | :arrow_up: | | [.../elide/runtime/intrinsics/js/node/FilesystemAPI.kt](https://app.codecov.io/gh/elide-dev/elide/pull/1072?src=pr&el=tree&filepath=packages%2Fgraalvm%2Fsrc%2Fmain%2Fkotlin%2Felide%2Fruntime%2Fintrinsics%2Fjs%2Fnode%2FFilesystemAPI.kt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev#diff-cGFja2FnZXMvZ3JhYWx2bS9zcmMvbWFpbi9rb3RsaW4vZWxpZGUvcnVudGltZS9pbnRyaW5zaWNzL2pzL25vZGUvRmlsZXN5c3RlbUFQSS5rdA==) | `85.71% <ø> (ø)` | | | [...de/runtime/gvm/internals/node/stream/NodeStream.kt](https://app.codecov.io/gh/elide-dev/elide/pull/1072?src=pr&el=tree&filepath=packages%2Fgraalvm%2Fsrc%2Fmain%2Fkotlin%2Felide%2Fruntime%2Fgvm%2Finternals%2Fnode%2Fstream%2FNodeStream.kt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev#diff-cGFja2FnZXMvZ3JhYWx2bS9zcmMvbWFpbi9rb3RsaW4vZWxpZGUvcnVudGltZS9ndm0vaW50ZXJuYWxzL25vZGUvc3RyZWFtL05vZGVTdHJlYW0ua3Q=) | `34.49% <0.00%> (ø)` | | | [...ntime/gvm/internals/node/buffer/GuestBufferView.kt](https://app.codecov.io/gh/elide-dev/elide/pull/1072?src=pr&el=tree&filepath=packages%2Fgraalvm%2Fsrc%2Fmain%2Fkotlin%2Felide%2Fruntime%2Fgvm%2Finternals%2Fnode%2Fbuffer%2FGuestBufferView.kt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev#diff-cGFja2FnZXMvZ3JhYWx2bS9zcmMvbWFpbi9rb3RsaW4vZWxpZGUvcnVudGltZS9ndm0vaW50ZXJuYWxzL25vZGUvYnVmZmVyL0d1ZXN0QnVmZmVyVmlldy5rdA==) | `81.81% <81.81%> (ø)` | | | [...de/runtime/gvm/internals/node/fs/NodeFilesystem.kt](https://app.codecov.io/gh/elide-dev/elide/pull/1072?src=pr&el=tree&filepath=packages%2Fgraalvm%2Fsrc%2Fmain%2Fkotlin%2Felide%2Fruntime%2Fgvm%2Finternals%2Fnode%2Ffs%2FNodeFilesystem.kt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev#diff-cGFja2FnZXMvZ3JhYWx2bS9zcmMvbWFpbi9rb3RsaW4vZWxpZGUvcnVudGltZS9ndm0vaW50ZXJuYWxzL25vZGUvZnMvTm9kZUZpbGVzeXN0ZW0ua3Q=) | `63.24% <0.00%> (ø)` | | | [...de/runtime/gvm/internals/node/buffer/GuestBytes.kt](https://app.codecov.io/gh/elide-dev/elide/pull/1072?src=pr&el=tree&filepath=packages%2Fgraalvm%2Fsrc%2Fmain%2Fkotlin%2Felide%2Fruntime%2Fgvm%2Finternals%2Fnode%2Fbuffer%2FGuestBytes.kt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev#diff-cGFja2FnZXMvZ3JhYWx2bS9zcmMvbWFpbi9rb3RsaW4vZWxpZGUvcnVudGltZS9ndm0vaW50ZXJuYWxzL25vZGUvYnVmZmVyL0d1ZXN0Qnl0ZXMua3Q=) | `57.14% <57.14%> (ø)` | | | [...e/runtime/intrinsics/js/node/buffer/BufferClass.kt](https://app.codecov.io/gh/elide-dev/elide/pull/1072?src=pr&el=tree&filepath=packages%2Fgraalvm%2Fsrc%2Fmain%2Fkotlin%2Felide%2Fruntime%2Fintrinsics%2Fjs%2Fnode%2Fbuffer%2FBufferClass.kt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev#diff-cGFja2FnZXMvZ3JhYWx2bS9zcmMvbWFpbi9rb3RsaW4vZWxpZGUvcnVudGltZS9pbnRyaW5zaWNzL2pzL25vZGUvYnVmZmVyL0J1ZmZlckNsYXNzLmt0) | `0.00% <0.00%> (ø)` | | | [...untime/intrinsics/js/node/buffer/BufferInstance.kt](https://app.codecov.io/gh/elide-dev/elide/pull/1072?src=pr&el=tree&filepath=packages%2Fgraalvm%2Fsrc%2Fmain%2Fkotlin%2Felide%2Fruntime%2Fintrinsics%2Fjs%2Fnode%2Fbuffer%2FBufferInstance.kt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev#diff-cGFja2FnZXMvZ3JhYWx2bS9zcmMvbWFpbi9rb3RsaW4vZWxpZGUvcnVudGltZS9pbnRyaW5zaWNzL2pzL25vZGUvYnVmZmVyL0J1ZmZlckluc3RhbmNlLmt0) | `75.75% <75.75%> (ø)` | | | [...me/gvm/internals/node/buffer/NodeBufferEncoding.kt](https://app.codecov.io/gh/elide-dev/elide/pull/1072?src=pr&el=tree&filepath=packages%2Fgraalvm%2Fsrc%2Fmain%2Fkotlin%2Felide%2Fruntime%2Fgvm%2Finternals%2Fnode%2Fbuffer%2FNodeBufferEncoding.kt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev#diff-cGFja2FnZXMvZ3JhYWx2bS9zcmMvbWFpbi9rb3RsaW4vZWxpZGUvcnVudGltZS9ndm0vaW50ZXJuYWxzL25vZGUvYnVmZmVyL05vZGVCdWZmZXJFbmNvZGluZy5rdA==) | `50.00% <50.00%> (ø)` | | | [...untime/gvm/internals/node/buffer/NodeHostBuffer.kt](https://app.codecov.io/gh/elide-dev/elide/pull/1072?src=pr&el=tree&filepath=packages%2Fgraalvm%2Fsrc%2Fmain%2Fkotlin%2Felide%2Fruntime%2Fgvm%2Finternals%2Fnode%2Fbuffer%2FNodeHostBuffer.kt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev#diff-cGFja2FnZXMvZ3JhYWx2bS9zcmMvbWFpbi9rb3RsaW4vZWxpZGUvcnVudGltZS9ndm0vaW50ZXJuYWxzL25vZGUvYnVmZmVyL05vZGVIb3N0QnVmZmVyLmt0) | `60.78% <60.78%> (ø)` | | | ... and [3 more](https://app.codecov.io/gh/elide-dev/elide/pull/1072?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev) | | ... and [11 files with indirect coverage changes](https://app.codecov.io/gh/elide-dev/elide/pull/1072/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev) ------ [Continue to review full report in Codecov by Sentry](https://app.codecov.io/gh/elide-dev/elide/pull/1072?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://app.codecov.io/gh/elide-dev/elide/pull/1072?dropdown=coverage&src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev). Last update [84ec973...40acda6](https://app.codecov.io/gh/elide-dev/elide/pull/1072?dropdown=coverage&src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=elide-dev).