Skip to content

Narrow browser and extension FFI messages / 收窄浏览器与扩展 FFI 消息 #37

Description

@tiye

English

Problem

After #36 removes the false Store decoder boundary and local alerts uses precise nominal hook schemas, seven msg-buffer-owned current-compiler findings remain:

  • Two event handlers dereference .-target from JsNullish values without narrowing.
  • main! compares raw document.visibilityState with a String.
  • listen-extension! compares four raw message.action values with Strings (menu-summary, fill-text, menu-translate, menu-custom).

These are all shallow host-boundary values and should not stay Dynamic inside application control flow.

Proposed migration

  • Define typed browser-event/message adapters that validate target/action/visibility fields at ingress.
  • Return Option<String> or a finite nominal action enum; pattern-match before dispatch.
  • Keep arbitrary deep extension payload data Dynamic only behind the decoded action-specific boundary.

Acceptance

  • No direct dereference of JsNullish event targets.
  • Visibility and extension action comparisons are statically homogeneous or nominal matches.
  • Existing send/reply/fill/translate behavior and startup output remain unchanged.
  • Do not solve the migration with broad unsafe-coerce or raw equality primitives.

中文

问题

#36 删除错误的 Store decoder 边界,并让本地 alerts 使用精确 nominal hook schema 后,当前编译器仍报告 7 条由 msg-buffer 自身负责的问题:

  • 两个事件 handler 未 narrow 就从 JsNullish 值读取 .-target
  • main! 把原始 document.visibilityState 与 String 比较。
  • listen-extension! 把四个原始 message.action 与 String 比较(menu-summaryfill-textmenu-translatemenu-custom)。

这些都是浅层 host-boundary 值,不应以 Dynamic 继续进入应用控制流。

建议迁移

  • 定义 typed browser-event/message adapter,在入口验证 target/action/visibility 字段。
  • 返回 Option<String> 或有限 nominal action enum,并在 dispatch 前 pattern match。
  • 只有 action-specific 边界之后的任意深层 extension payload 才保留 Dynamic。

验收

  • 不再直接解引用 JsNullish event target。
  • visibility 与 extension action 使用静态同类型比较或 nominal match。
  • 现有发送、reply、fill、translate 行为与启动输出保持不变。
  • 不用宽泛 unsafe-coerce 或底层 raw equality primitive 规避迁移。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions