fix!: isolate DSL class tags across addons - #67
Draft
GrapeBaBa wants to merge 1 commit into
Draft
Conversation
GrapeBaBa
force-pushed
the
fix/isolate-addon-type-tags
branch
from
July 28, 2026 01:32
9f761f5 to
cfd74ce
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
napi_type_tagvalues from stable content identities instead of process-local addresses.type_tagsalt injs.exportModuleand allow per-class overrides injs.classmod.Counterclasses cannot cross the native pointer boundaryProblem
DSL class tags were derived only from
@typeName(T). Separate addons conventionally rooted atmod.zigcan both containmod.Counter, producing the same tag. An exported function accepting*Countercould then accept an object from the other addon, passnapi_check_object_type_tag, and reinterpret unrelated native memory as its own class.An address-based tag isolates simultaneously loaded addons but changes after unload/reload, which does not satisfy Node-API's stable type-tag contract.
Approach
This follows napi-rs' content-identity approach from napi-rs#3405:
{salt}::{@typeName(T)}with 128-bit FNV-1anapi_type_tag.lowerand.upperjs.class(.{ .type_tag = "..." })replace the module salt for one classZig does not expose Cargo-like package name/version metadata to imported source modules, so zapi requires the addon identity explicitly:
The salt should be generated once and kept stable. A UUID is recommended.
Breaking change
DSL addons using
js.exportModulemust add.type_tag. Low-levelnapi.module.registerusers are unchanged.Testing
pnpm buildpnpm test— 117 tests passedzig build test:zapi -Doptimize=ReleaseSafezig fmt --check ...pnpm lint:js