Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console.log can't non-string arguments #120

Closed
mhmd-azeez opened this issue Jan 12, 2025 · 0 comments · Fixed by #121
Closed

console.log can't non-string arguments #120

mhmd-azeez opened this issue Jan 12, 2025 · 0 comments · Fixed by #121

Comments

@mhmd-azeez
Copy link
Contributor

Repro:

export function greet() {
  const n = 1;
  tryPrint('n + 1', n + 1);
  tryPrint('multiple string args', 'one', 'two', 'three');
  tryPrint('single n', n);
  tryPrint('three ns', n, n, n);
  tryPrint('n with label', 'n', n);
  tryPrint('boolean', true);
  tryPrint('null', null);
  tryPrint('undefined', undefined);
  tryPrint('empty object', {});
  tryPrint('empty array', []);
  tryPrint('object with key', { key: 'value' });
}

function tryPrint(text: string, ...args: any[]) {
  try {
    console.log(...args);
    console.log(`${text} - ✅`);
  } catch (e) {
    console.log(`${text} - ❌ - ${(e as any).message}`);
  }
  console.log('------')
}

v1.3.3:

mo@mo-dylibso:/mnt/d/x/extism/ts_plugin$ extism-js --version
extism-js 1.3.3
mo@mo-dylibso:/mnt/d/x/extism/ts_plugin$ npm run build && npm run test

> js-pdk-template@1.0.0 build
> tsc --noEmit && node esbuild.js && extism-js dist/index.js -i src/index.d.ts -o dist/plugin.wasm


> js-pdk-template@1.0.0 test
> extism call dist/plugin.wasm greet --input 'Mo' --wasi --log-level debug

2025/01/12 20:27:45 Calling function : greet
2025/01/12 20:27:45 n + 1 - ❌ - QuickJS library created a unknown error
2025/01/12 20:27:45 ------
2025/01/12 20:27:45 one two three
2025/01/12 20:27:45 multiple string args - ✅
2025/01/12 20:27:45 ------
2025/01/12 20:27:45 single n - ❌ - QuickJS library created a unknown error
2025/01/12 20:27:45 ------
2025/01/12 20:27:45 three ns - ❌ - QuickJS library created a unknown error
2025/01/12 20:27:45 ------
2025/01/12 20:27:45 n with label - ❌ - QuickJS library created a unknown error
2025/01/12 20:27:45 ------
2025/01/12 20:27:45 boolean - ❌ - QuickJS library created a unknown error
2025/01/12 20:27:45 ------
2025/01/12 20:27:45 null - ❌ - QuickJS library created a unknown error
2025/01/12 20:27:45 ------
2025/01/12 20:27:45 undefined - ❌ - QuickJS library created a unknown error
2025/01/12 20:27:45 ------
2025/01/12 20:27:45 empty object - ❌ - QuickJS library created a unknown error
2025/01/12 20:27:45 ------
2025/01/12 20:27:45 empty array - ❌ - QuickJS library created a unknown error
2025/01/12 20:27:45 ------
2025/01/12 20:27:45 object with key - ❌ - QuickJS library created a unknown error
2025/01/12 20:27:45 ------

v1.2.0:

mo@mo-dylibso:/mnt/d/x/extism/ts_plugin$ extism-js --version
extism-js 1.2.0
mo@mo-dylibso:/mnt/d/x/extism/ts_plugin$ npm run build && npm run test

> js-pdk-template@1.0.0 build
> tsc --noEmit && node esbuild.js && extism-js dist/index.js -i src/index.d.ts -o dist/plugin.wasm


> js-pdk-template@1.0.0 test
> extism call dist/plugin.wasm greet --input 'Mo' --wasi --log-level debug

2025/01/12 20:28:41 Calling function : greet
2025/01/12 20:28:41 2
2025/01/12 20:28:41 n + 1 - ✅
2025/01/12 20:28:41 ------
2025/01/12 20:28:41 one two three
2025/01/12 20:28:41 multiple string args - ✅
2025/01/12 20:28:41 ------
2025/01/12 20:28:41 1
2025/01/12 20:28:41 single n - ✅
2025/01/12 20:28:41 ------
2025/01/12 20:28:41 1 1 1
2025/01/12 20:28:41 three ns - ✅
2025/01/12 20:28:41 ------
2025/01/12 20:28:41 n 1
2025/01/12 20:28:41 n with label - ✅
2025/01/12 20:28:41 ------
2025/01/12 20:28:41 true
2025/01/12 20:28:41 boolean - ✅
2025/01/12 20:28:41 ------
2025/01/12 20:28:41 null
2025/01/12 20:28:41 null - ✅
2025/01/12 20:28:41 ------
2025/01/12 20:28:41 undefined
2025/01/12 20:28:41 undefined - ✅
2025/01/12 20:28:41 ------
2025/01/12 20:28:41 [object Object]
2025/01/12 20:28:41 empty object - ✅
2025/01/12 20:28:41 ------
2025/01/12 20:28:41
2025/01/12 20:28:41 empty array - ✅
2025/01/12 20:28:41 ------
2025/01/12 20:28:41 [object Object]
2025/01/12 20:28:41 object with key - ✅
2025/01/12 20:28:41 ------
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 a pull request may close this issue.

1 participant