Skip to content

Add experimental scoped native access API - #216

Merged
dokar3 merged 5 commits into
mainfrom
feature/native-access
Aug 7, 2026
Merged

Add experimental scoped native access API#216
dokar3 merged 5 commits into
mainfrom
feature/native-access

Conversation

@dokar3

@dokar3 dokar3 commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added experimental native-context access for synchronous QuickJS operations.
    • Added automatic native cleanup callbacks when a runtime closes, with predictable reverse-order cleanup.
    • Added support for mixed Kotlin/JVM, Kotlin/Native, and native bindings.
    • Improved native library support across supported platforms, including Windows.
    • Documented native-context usage, lifecycle restrictions, and platform-specific behavior.
  • Tests

    • Added cross-platform integration coverage for evaluation, bindings, modules, cleanup behavior, and runtime lifecycle.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3355a7f2-e995-43b3-8338-968a83770dd3

📥 Commits

Reviewing files that changed from the base of the PR and between d0adf7d and ab2cbcb.

📒 Files selected for processing (2)
  • integration-test/native-access/build.gradle.kts
  • integration-test/native-access/native/CMakeLists.txt
🚧 Files skipped from review as they are similar to previous changes (1)
  • integration-test/native-access/build.gradle.kts

📝 Walkthrough

Walkthrough

The PR adds experimental native-context access and native cleanup callbacks for JVM and Kotlin/Native. It separates general and native-access integration tests. It adds published-artifact extraction, native build wiring, and native binding tests.

Changes

Native context API and lifecycle

Layer / File(s) Summary
Native context API and lifecycle
README.md, quickjs/src/commonMain/..., quickjs/src/jniMain/..., quickjs/src/nativeMain/..., quickjs/native/jni/...
QuickJs provides withNativeContext and onNativeClose. Contexts expose platform-specific addresses or pointers. Cleanup callbacks run in reverse order before resource release. The first cleanup failure is rethrown after release.

General integration execution

Layer / File(s) Summary
General integration execution
settings.gradle.kts, integration-test/general/...
The general module tests evaluation, bindings, modules, converters, memory, lifecycle behavior, and coroutine execution. JVM and GraalVM tasks use extracted published QuickJS artifacts.

Native-access build and platform wiring

Layer / File(s) Summary
Native-access build and platform wiring
integration-test/native-access/..., quickjs/native/...
The native-access module extracts host-specific QuickJS artifacts, prepares headers, builds the native library, and configures JVM and Kotlin/Native test paths. Windows builds include QuickJS export definitions.

Native binding operations and validation

Layer / File(s) Summary
Native binding operations and validation
integration-test/native-access/src/..., integration-test/native-access/native/native_operations.*
The integration adds C, JNI, JVM, and Kotlin/Native operations for installing, executing, and removing QuickJS bindings. Tests verify numeric results, injected values, cleanup counts, and reverse cleanup ordering.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant QuickJs
  participant QuickJsNativeContext
  participant NativeOperations
  participant QuickJsClose
  QuickJs->>QuickJsNativeContext: withNativeContext(callback)
  QuickJsNativeContext->>NativeOperations: pass context and runtime addresses
  NativeOperations-->>QuickJsNativeContext: execute native operation
  QuickJs->>QuickJsClose: close()
  QuickJsClose->>NativeOperations: invoke cleanup callbacks in reverse order
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.88% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding an experimental scoped native access API.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/native-access

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dokar3

dokar3 commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai help

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

CodeRabbit commands

These commands are invoked using PR/Issue comments.

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai rate limit to show your current review rate limit status.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai evaluate custom pre-merge check --instructions <custom-checks-instructions> --name <custom-checks-title> [--mode <error|warning>] to validate the custom pre-merge checks instructions. Defaults to error when --mode is omitted.
  • @coderabbitai ignore pre-merge checks to override pre-merge checks and get an approval on PR.
  • @coderabbitai run pre-merge checks to run pre-merge checks on the pull request.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai emit path instructions to emit generated path-specific review instructions for this repository.
  • @coderabbitai resolve merge conflict to automatically resolve merge conflicts.
  • @coderabbitai autofix to automatically fix issues identified in unresolved review comments.
  • @coderabbitai fix-ci to automatically fix failing CI checks in a stacked pull request.
  • @coderabbitai fix-ci commit to automatically fix failing CI checks by committing fixes to the current branch.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai generate configuration to create a PR that adds the current resolved configuration as .coderabbit.yaml (or show it if already present).
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit configuration file (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, support, documentation and community

  • Visit our status page to check the current availability of CodeRabbit.
  • Create a ticket on our support page for assistance with any issues or questions.
  • Visit our documentation site for detailed information on how to use CodeRabbit.
  • Join our Discord community to connect with other users and get help from the community.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@integration-test/native-access/native/native_operations.c`:
- Line 18: Update native_sum so left and right are promoted and added using
int64_t before constructing the QuickJS result, then pass that accumulated
result through the appropriate QuickJS integer API instead of evaluating left +
right as int32_t.

In `@quickjs/src/jniMain/kotlin/com/dokar/quickjs/QuickJsNativeContext.jni.kt`:
- Around line 5-8: Update the KDoc for contextAddress and runtimeAddress in
QuickJsNativeContext to state that both addresses are valid only during the
QuickJs.withNativeContext callback and must not be retained or used after the
callback returns.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d3c426a9-ab7e-4619-a9b6-5a157592d066

📥 Commits

Reviewing files that changed from the base of the PR and between c055d6f and e96fb55.

📒 Files selected for processing (21)
  • README.md
  • integration-test/general/build.gradle.kts
  • integration-test/general/src/commonMain/kotlin/com/dokar/quickjs/integration/QuickJsIntegrationScenario.kt
  • integration-test/general/src/commonTest/kotlin/QuickJsIntegrationTest.kt
  • integration-test/general/src/jvmMain/kotlin/com/dokar/quickjs/integration/Main.kt
  • integration-test/native-access/build.gradle.kts
  • integration-test/native-access/native/CMakeLists.txt
  • integration-test/native-access/native/native_operations.c
  • integration-test/native-access/native/native_operations.h
  • integration-test/native-access/src/commonTest/kotlin/com/dokar/quickjs/nativeintegration/NativeOperations.kt
  • integration-test/native-access/src/commonTest/kotlin/com/dokar/quickjs/nativeintegration/NativeOperationsTest.kt
  • integration-test/native-access/src/jvmTest/kotlin/com/dokar/quickjs/nativeintegration/NativeOperations.jvm.kt
  • integration-test/native-access/src/nativeTest/kotlin/com/dokar/quickjs/nativeintegration/NativeOperations.native.kt
  • quickjs/native/jni/quickjs_jni.c
  • quickjs/src/commonMain/kotlin/com/dokar/quickjs/ExperimentalQuickJsApi.kt
  • quickjs/src/commonMain/kotlin/com/dokar/quickjs/QuickJs.kt
  • quickjs/src/jniMain/kotlin/com/dokar/quickjs/QuickJs.jni.kt
  • quickjs/src/jniMain/kotlin/com/dokar/quickjs/QuickJsNativeContext.jni.kt
  • quickjs/src/nativeMain/kotlin/com/dokar/quickjs/QuickJs.native.kt
  • quickjs/src/nativeMain/kotlin/com/dokar/quickjs/QuickJsNativeContext.native.kt
  • settings.gradle.kts

Comment thread integration-test/native-access/native/native_operations.c Outdated
Comment thread quickjs/src/jniMain/kotlin/com/dokar/quickjs/QuickJsNativeContext.jni.kt Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@integration-test/general/build.gradle.kts`:
- Around line 99-124: Update the extractQuickJsLibrary task to delete
quickJsExtractedDir before copying, preventing stale extracted files from
persisting. After the copy, verify that both the platform-specific native
library and the META-INF/native-image/com.dokar.quickjs/quickjs metadata
directory exist, and fail the task with a clear error if either required entry
is missing.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e433bf3f-ba42-4167-95ad-0b077d2e1ab4

📥 Commits

Reviewing files that changed from the base of the PR and between 4cb2b19 and fb3bbc6.

📒 Files selected for processing (5)
  • integration-test/general/build.gradle.kts
  • integration-test/native-access/build.gradle.kts
  • integration-test/native-access/native/CMakeLists.txt
  • quickjs/native/CMakeLists.txt
  • quickjs/native/quickjs.def

Comment thread integration-test/general/build.gradle.kts
@dokar3
dokar3 merged commit 140ece1 into main Aug 7, 2026
4 checks passed
@dokar3
dokar3 deleted the feature/native-access branch August 7, 2026 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant