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

Update console.log implementation to support multiple params #80

Merged

Conversation

ubiquitous-dev
Copy link
Contributor

Issue Summary

This PR fixes a couple of incompatibilities between the console.debug/log/warn/error statements. console.log("a", "b", "c"); in the exits js-pdk does not output the expected a b c but just outputs a. also, an empty console.log errors out, but it normally is a no-op.

Test script

  console.debug();
  console.debug("debug: single console statement");
  console.debug("debug:", "multiple", "console", "statements");

  console.log();
  console.log("log: single console statement");
  console.log("log:", "multiple", "console", "statements");

  console.warn();
  console.warn("warn: single console statement");
  console.warn("warn:", "multiple", "console", "statements");

  console.error();
  console.error("error: single console statement");
  console.error("error:", "multiple", "console", "statements");

Output in chrome devtools

image

Output in current js-pdk

2024/05/26 11:18:19 Calling function : greet
Error: Uncaught InternalError: Need at least one arg
    at greet (script.js:43)

note that the no-op behavior of an empty call is not present here and it instead errors.

Output in current js-pdk with empty calls removed

2024/05/26 11:19:26 debug: single console statement
2024/05/26 11:19:26 debug:
2024/05/26 11:19:26 log: single console statement
2024/05/26 11:19:26 log:
2024/05/26 11:19:26 warn: single console statement
2024/05/26 11:19:26 warn:
2024/05/26 11:19:26 error: single console statement
2024/05/26 11:19:26 error:

note the multi-statement lines do not print all arguments.

Output with the code change from the PR (including empty statements)

024/05/26 11:23:07 Calling function : greet
2024/05/26 11:23:08 debug: single console statement
2024/05/26 11:23:08 debug: multiple console statements
2024/05/26 11:23:08 log: single console statement
2024/05/26 11:23:08 log: multiple console statements
2024/05/26 11:23:08 warn: single console statement
2024/05/26 11:23:08 warn: multiple console statements
2024/05/26 11:23:08 error: single console statement
2024/05/26 11:23:08 error: multiple console statements

note that the empty statements are properly no-ops, and the multiple args are properly printed.

@bhelx
Copy link
Contributor

bhelx commented May 26, 2024

Closes #70

@ubiquitous-dev
Copy link
Contributor Author

@bhelx anything else you'd like to see to make this a candidate for merging? I keep forgetting that console.log doesn't take multiple parameters in the pdk

@bhelx bhelx merged commit 2240f28 into extism:main Jun 3, 2024
2 checks passed
@bhelx
Copy link
Contributor

bhelx commented Jun 3, 2024

Apologies. I thought I merged it already!

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.

None yet

2 participants