Skip to content

String arguments corrupted when passed to cross-module functions inside callback scopes #12

Description

@proggeramlug

Bug Description

String literals and string variables passed as arguments to imported functions (cross-module calls) are corrupted to empty strings when called from inside a button click handler or other callback scope. The same calls work correctly at module initialization (top-level scope).

Reproduction

import { saveState, getState } from './data/store';

// This WORKS — module level:
saveState('key1', 'hello');       // stores 'hello' ✓
console.log(getState('key1'));    // returns 'hello' ✓

const btn = Button('Test', () => {
  // This FAILS — inside callback:
  saveState('key2', 'world');     // stores '' (empty) ✗
  console.log(getState('key2'));  // returns '' ✗
});

Verified via SQLite:

SELECT * FROM app_state;
-- key1|hello        -- module level: correct
-- key2|             -- callback scope: empty!

Impact

Any cross-module function call with string arguments inside a callback/closure receives empty or corrupted values. This affects:

  • saveState(key, value) — value is empty
  • createConnection({ name, host, ... }) — some fields are empty
  • encodeURIComponent(str) — produces "undefined"

Likely Cause

The NaN-boxed string pointer (f64) is being stored as an i64 (raw pointer) in the local variable due to is_string optimization. When passed as an argument to a cross-module function that expects f64, the i64→f64 bitcast produces a different value than the original NaN-boxed f64. Related to #10.

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