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

Avoid using 'eval' for statically known strings #24

Merged
merged 3 commits into from
Mar 19, 2024

Conversation

OlivierNicole
Copy link
Collaborator

When using functions such as Js.Unsafe.eval_string in Wasm, when the string is known at compile time, it can be emitted as an external Javascript fragment, rather than using the infamous eval.

When using functions such as `Js.Unsafe.eval_string` in Wasm, when the
string is known at compile time, it can be emitted as an external
Javascript fragment, rather than using the infamous `eval`.

Co-authored-by: Jérôme Vouillon <jerome.vouillon@gmail.com>
@vouillon
Copy link
Collaborator

Could you reformat compiler/lib/wasm/wa_gc_target.ml and fix the whitespace changes in runtime/wasm/runtime.js?

@OlivierNicole
Copy link
Collaborator Author

Done.

Comment on lines 363 to 383
start_fiber = wrap_fun(
{parameters: ['eqref'], results: ['externref']},
caml_start_fiber, {promising: 'first'}
)
var _initialize = wrap_fun(
{parameters: [], results: ['externref']},
_initialize, {promising: 'first'}
)
var process = globalThis.process;
if(process && process.on) {
process.on('uncaughtException', (err, origin) =>
caml_handle_uncaught_exception(err))
}
else if(globalThis.addEventListener){
globalThis.addEventListener('error', event=>
event.error&&caml_handle_uncaught_exception(event.error))
}
await _initialize();
})(((joo_global_object,jsoo_exports,globalThis)=>(x)=>{return eval("("+x+")")})(globalThis,globalThis?.module?.exports||globalThis,globalThis),
PRIMITIVES, STRINGS,
((joo_global_object,jsoo_exports,globalThis)=>FRAGMENTS)(globalThis,globalThis?.module?.exports||globalThis,globalThis))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This, also...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what happened here. I think it should be right now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vouillon I don’t really understand this file, so I don’t remember what was the right way to do this.

runtime/wasm/runtime.js Outdated Show resolved Hide resolved
Co-authored-by: Jérôme Vouillon <jerome.vouillon@gmail.com>
@vouillon vouillon merged commit 653dfc7 into ocaml-wasm:main Mar 19, 2024
2 checks passed
@OlivierNicole OlivierNicole deleted the avoid_eval branch March 22, 2024 13:43
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