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

Passing an exception into ccall as string sends empty string #17766

Open
SoylentGraham opened this issue Aug 31, 2022 · 5 comments
Open

Passing an exception into ccall as string sends empty string #17766

SoylentGraham opened this issue Aug 31, 2022 · 5 comments

Comments

@SoylentGraham
Copy link

SoylentGraham commented Aug 31, 2022

Version of emscripten/emsdk: 3.1.20-git (from homebrew)

This is user-error, but feels like it should have been caught higher up (maybe in the string/stack alloc?), and should be a simple UX fix

I passed an exception into ccall;

	const ReturnType = null;
	const ArgTypes = ['number','string'];
	const ArgValues = [Handle,Error];
	try
	{
		Module.ccall('OnStreamingDownloadFinished',ReturnType,ArgTypes,ArgValues);
	}
	catch(e)
	{...}

Didn't twig it wasn't a string for a while as chrome's debugger shows it as a string, the type convertor doesn't error, (and debugger even makes it look like a string), and it manages to allocate & copy a string (of length 1) because
var len = (str.length << 2) + 1; -->
var len = (undefined << 2) + 1; == 1

Feels to me like either
a) convertor should throw if object has no length property (or just isn't a string!) thereby forcing users to pass strings if they said they would
b) force the input value to be a string str = ${str}` (so type takes precedent)

Screenshot 2022-08-31 at 15 26 14
(Screenshot to highlight UX)

@sbc100
Copy link
Collaborator

sbc100 commented Sep 1, 2022

Certainly seems like we could use an assert about the type of str there. If you have time perhaps you would like to open PR to add that?

@SoylentGraham
Copy link
Author

I haven't tried building the compiler before; Is this the code I need to change? (I assume this isn't auto-generated code?)

$ccall: function(ident, returnType, argTypes, args, opts) {

@sbc100
Copy link
Collaborator

sbc100 commented Sep 1, 2022

Yes, that is the where the ccall code lives.

@SoylentGraham
Copy link
Author

Also, is a) your preferred resolution? (stop users making errors, rather than possibly invoking unexpected string conversions - which I probably better for unit tests too)

@sbc100
Copy link
Collaborator

sbc100 commented Sep 1, 2022

I think an assert is the right solution here.

Ishant-Modi added a commit to Ishant-Modi/emscripten that referenced this issue Apr 2, 2023
Ishant-Modi added a commit to Ishant-Modi/emscripten that referenced this issue Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants