Skip to content

Commit 13d5c69

Browse files
committed
fixup! Wasm runtime: provide access to JavaScript eval function
1 parent a546173 commit 13d5c69

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

runtime/wasm/jslib.wat

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101
(func $caml_copy_nativeint (param i32) (result (ref eq))))
102102
(import "int32" "Nativeint_val"
103103
(func $Nativeint_val (param (ref eq)) (result i32)))
104+
(import "string" "caml_string_concat"
105+
(func $caml_string_concat (param (ref eq) (ref eq)) (result (ref eq))))
104106

105107
(type $block (array (mut (ref eq))))
106108
(type $float (struct (field f64)))
@@ -129,13 +131,22 @@
129131
(ref.i31 (call $strict_equals
130132
(call $unwrap (local.get 0)) (call $unwrap (local.get 1)))))
131133

132-
(func (export "caml_js_expr") (export "caml_pure_js_expr")
133-
(export "caml_js_var") (export "caml_js_eval_string")
134-
(param (ref eq)) (result (ref eq))
134+
(func $caml_js_eval_string (export "caml_js_eval_string")
135+
(param $vs (ref eq)) (result (ref eq))
135136
(local $s (ref $bytes))
136-
(local.set $s (ref.cast (ref $bytes) (local.get 0)))
137+
(local.set $s (ref.cast (ref $bytes) (local.get $vs)))
137138
(return_call $wrap (call $eval (call $jsstring_of_bytes (local.get $s)))))
138139

140+
(@string $rparen "(")
141+
(@string $lparen ")")
142+
143+
(func (export "caml_js_expr") (export "caml_pure_js_expr")
144+
(export "caml_js_var")
145+
(param $s (ref eq)) (result (ref eq))
146+
(return_call $caml_js_eval_string
147+
(call $caml_string_concat (global.get $rparen)
148+
(call $caml_string_concat (local.get $s) (global.get $lparen)))))
149+
139150
(func (export "caml_js_global") (param (ref eq)) (result (ref eq))
140151
(call $wrap (global.get $global_this)))
141152

runtime/wasm/runtime.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@
212212
// biome-ignore lint/suspicious/noDoubleEquals:
213213
equals: (x, y) => x == y,
214214
// biome-ignore lint/security/noGlobalEval:
215-
eval: (x) => eval?.('"use strict";(' + x + ")"),
215+
eval: (x) => eval?.('"use strict";' + x),
216216
strict_equals: (x, y) => x === y,
217217
fun_call: (f, o, args) => f.apply(o, args),
218218
meth_call: (o, f, args) => o[f].apply(o, args),

0 commit comments

Comments
 (0)