emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.63k stars 3.28k forks source link

Documentation about Module.arguments may need to be improved #21082

Open ChinYikMing opened 8 months ago

ChinYikMing commented 8 months ago

The current documentation about Module.arguments is not clear enough, see doc. You will receive "undefined" if you use Module.arguments straight in prejs because the documentation doesn't indicate that you should initialize it first, for example:

Module['arguments'].push("-k");
Module['arguments'].push("Image");
Module['arguments'].push("-b");
Module['arguments'].push("minimal.dtb");
Module['arguments'].push("-i");
Module['arguments'].push("rootfs.cpio");

Initializing Module.arguments before utilizing it in prejs is the proper usage procedure:

Module['arguments'] = []
Module['arguments'].push("-k");
Module['arguments'].push("Image");
Module['arguments'].push("-b");
Module['arguments'].push("minimal.dtb");
Module['arguments'].push("-i");
Module['arguments'].push("rootfs.cpio");

Related to: #11239

sbc100 commented 8 months ago

Yes, this is true for all attributes on the incoming module object. The attributes don't exist in pre-js files until you set them. Perhaps the docs can be updated to make this more clear.

sbc100 commented 8 months ago

Is there somewhere that you read that it was OK to assume the existence of these properties during pre-js? I.e. are there any other places that might need updating?

ChinYikMing commented 8 months ago

I believe there are still a few points that need to be made clear. I will follow up this issue once I figure out more.