1pub mod binary;
5pub mod call_member;
6pub mod container;
7pub mod template_new;
8
9use crate::zigir::emit::Emitter;
10use crate::zigir::emit::helpers as emit_helpers;
11use crate::zigir::emit::helpers::{EmitterHelpers, escape_zig_string, update_op_to_zig};
12
13impl Emitter {
18 pub(crate) fn emit_expr(&mut self, expr: &crate::zigir::types::IrExpr) {
19 match expr {
20 crate::zigir::types::IrExpr::IntLiteral(n) => {
21 self.write(&n.to_string());
22 }
23
24 crate::zigir::types::IrExpr::FloatLiteral(n) => {
25 if *n == -0.0 && n.is_sign_negative() {
26 self.write("-0.0");
27 } else {
28 self.write(&n.to_string());
29 }
30 }
31
32 crate::zigir::types::IrExpr::StringLiteral(s) => {
33 self.write(&format!("\"{}\"", escape_zig_string(s)));
34 }
35
36 crate::zigir::types::IrExpr::BoolLiteral(b) => {
37 self.write(if *b { "true" } else { "false" });
38 }
39
40 crate::zigir::types::IrExpr::BigIntLiteral(s) => {
41 self.write(&format!(
44 "(js_bigint.JsBigInt.init(js_allocator.allocator(), \"{}\") catch @panic(\"OOM: BigInt init\"))",
45 escape_zig_string(s)
46 ));
47 }
48
49 crate::zigir::types::IrExpr::Null => {
50 self.write("JsAny.fromNull()");
51 }
52
53 crate::zigir::types::IrExpr::Undefined => {
54 self.write("JsAny.fromUndefined()");
55 }
56
57 crate::zigir::types::IrExpr::Ident(ident) => {
58 self.write(&ident.zig_name);
59 }
60
61 crate::zigir::types::IrExpr::This => {
62 self.write("self");
63 }
64
65 crate::zigir::types::IrExpr::Binary {
67 op,
68 left,
69 right,
70 left_type,
71 right_type,
72 } => {
73 use crate::types::ZigType;
74 use crate::zigir::ops::BinOp;
75
76 let lt = left_type.as_ref();
78 let rt = right_type.as_ref();
79 let left_is_bigint = lt == Some(&ZigType::BigInt);
80 let right_is_bigint = rt == Some(&ZigType::BigInt);
81 let left_is_str = lt == Some(&ZigType::Str)
85 || matches!(&**left, crate::zigir::types::IrExpr::StringLiteral(_));
86 let right_is_str = rt == Some(&ZigType::Str)
87 || matches!(&**right, crate::zigir::types::IrExpr::StringLiteral(_));
88 let left_is_jsany = lt == Some(&ZigType::JsAny);
89 let right_is_jsany = rt == Some(&ZigType::JsAny);
90 let left_is_float = lt == Some(&ZigType::F64);
91 let right_is_float = rt == Some(&ZigType::F64);
92 let left_is_anytype = lt == Some(&ZigType::Anytype);
95 let right_is_anytype = rt == Some(&ZigType::Anytype);
96 let cross_type_known = lt.is_some()
97 && rt.is_some()
98 && lt != rt
99 && !left_is_bigint
100 && !right_is_bigint
101 && !left_is_anytype
102 && !right_is_anytype;
103 let str_vs_numeric = (left_is_str && !right_is_str && !right_is_bigint)
104 || (right_is_str && !left_is_str && !left_is_bigint);
105
106 if left_is_bigint && right_is_bigint {
108 self.emit_bigint_binary(*op, left, right);
109 }
110 else if *op == BinOp::Add
114 && ((left_is_str && right_is_bigint) || (left_is_bigint && right_is_str))
115 {
116 self.emit_bigint_string_concat(left, right, left_is_str);
117 }
118 else if (left_is_bigint || right_is_bigint)
122 && matches!(
123 op,
124 BinOp::Add
125 | BinOp::Sub
126 | BinOp::Mul
127 | BinOp::Div
128 | BinOp::Mod
129 | BinOp::Pow
130 | BinOp::BitAnd
131 | BinOp::BitOr
132 | BinOp::BitXor
133 | BinOp::Shl
134 | BinOp::Shr
135 )
136 {
137 self.write(
138 "@panic(\"TypeError: Cannot mix BigInt and other types, consider explicit conversions\")",
139 );
140 }
141 else if left_is_str && right_is_str {
143 self.emit_string_comparison(*op, left, right);
144 }
145 else if (left_is_bigint || right_is_bigint)
148 && matches!(
149 op,
150 BinOp::Eq
151 | BinOp::Ne
152 | BinOp::StrictEq
153 | BinOp::StrictNe
154 | BinOp::Lt
155 | BinOp::Le
156 | BinOp::Gt
157 | BinOp::Ge
158 )
159 {
160 self.emit_bigint_cross_comparison(
161 *op,
162 left,
163 right,
164 left_is_bigint,
165 right_is_bigint,
166 );
167 }
168 else if (cross_type_known || str_vs_numeric)
177 && matches!(
178 op,
179 BinOp::Eq
180 | BinOp::Ne
181 | BinOp::StrictEq
182 | BinOp::StrictNe
183 | BinOp::Lt
184 | BinOp::Le
185 | BinOp::Gt
186 | BinOp::Ge
187 )
188 {
189 self.emit_jsany_comparison(*op, left, right, false, false);
192 }
193 else if (left_is_jsany || right_is_jsany)
195 && matches!(
196 op,
197 BinOp::Eq
198 | BinOp::Ne
199 | BinOp::StrictEq
200 | BinOp::StrictNe
201 | BinOp::Lt
202 | BinOp::Le
203 | BinOp::Gt
204 | BinOp::Ge
205 )
206 {
207 self.emit_jsany_comparison(*op, left, right, left_is_jsany, right_is_jsany);
208 }
209 else if *op == BinOp::Div || *op == BinOp::Mod {
211 if left_is_float || right_is_float {
212 self.write("(");
213 self.emit_expr(left);
214 self.write(&format!(" {} ", if *op == BinOp::Div { "/" } else { "%" }));
215 self.emit_expr(right);
216 self.write(")");
217 } else {
218 self.write(&format!(
219 "{}(",
220 if *op == BinOp::Div {
221 "@divTrunc"
222 } else {
223 "@rem"
224 }
225 ));
226 self.emit_expr(left);
227 self.write(", ");
228 self.emit_expr(right);
229 self.write(")");
230 }
231 }
232 else if *op == BinOp::UrShr && (left_is_bigint || right_is_bigint) {
235 self.write(
236 "@panic(\"TypeError: BigInt does not support unsigned right shift (>>>)\")",
237 );
238 }
239 else if *op == BinOp::UrShr {
241 self.write("@as(i64, @intCast(@as(u32, @bitCast(@as(i32, @truncate(");
242 self.emit_expr(left);
243 self.write(")))) >> @intCast(");
244 self.emit_expr(right);
245 self.write(" & 31)))");
246 }
247 else if *op == BinOp::In {
249 self.emit_expr(right);
251 self.write(".contains(");
252 self.emit_expr(left);
253 self.write(")");
254 }
255 else {
257 self.emit_default_binop(*op, left, right);
258 }
259 }
260
261 crate::zigir::types::IrExpr::PowExpr {
262 base,
263 exp,
264 base_type,
265 exp_type,
266 result_type,
267 } => {
268 let pow_id = self.peek_label_id();
271 let blk = self.next_label();
272 if let Some(crate::types::ZigType::I64) = result_type {
274 self.write("@as(i64, @intFromFloat(");
275 }
276 self.write(&format!("({blk}: {{ "));
277 self.write(&format!("const _base_f64_{pow_id}: f64 = "));
278 self.emit_float_conversion(base, base_type);
279 self.write(&format!("; const _exp_f64_{pow_id}: f64 = "));
280 self.emit_float_conversion(exp, exp_type);
281 self.write(&format!(
282 "; break :{blk} std.math.pow(f64, _base_f64_{pow_id}, _exp_f64_{pow_id}); }})",
283 ));
284 if let Some(crate::types::ZigType::I64) = result_type {
285 self.write("))");
286 }
287 }
288
289 crate::zigir::types::IrExpr::Unary { op, operand } => {
290 match op {
291 crate::zigir::ops::UnaOp::Neg => {
292 self.write("-");
293 self.emit_expr(operand);
294 }
295 crate::zigir::ops::UnaOp::Not => {
296 self.write("!");
297 self.emit_expr_as_bool(operand);
300 }
301 crate::zigir::ops::UnaOp::BitNot => {
302 self.write("~@as(i32, @intCast(");
305 self.emit_expr(operand);
306 self.write("))");
307 }
308 crate::zigir::ops::UnaOp::Void => {
309 self.emit_expr(operand);
311 }
312 _ => unreachable!("typeof/delete should be resolved at lower time"),
317 }
318 }
319
320 crate::zigir::types::IrExpr::Logical {
321 op,
322 left,
323 right,
324 left_type,
325 right_type,
326 } => {
327 let id = self.peek_label_id();
335 let blk = self.next_label();
336 let lt = left_type.as_ref();
337 let rt = right_type.as_ref();
338 let same_type = lt.is_some() && rt.is_some() && lt == rt;
339
340 self.write(&format!("({blk}: {{ const _lv_{id}"));
345 if same_type {
346 self.write(&format!(": {}", lt.unwrap().to_zig_type()));
347 }
348 self.write(" = ");
349 self.emit_expr(left);
350 self.write("; ");
351
352 match op {
353 crate::zigir::ops::LogicalOp::And => {
354 self.write("if (js_runtime.isTruthy(_lv_");
356 self.write(&format!("{id}))"));
357 self.write(&format!(" break :{blk} "));
358 if same_type {
359 self.emit_expr(right);
360 } else {
361 self.write("JsAny.from(");
362 self.emit_expr(right);
363 self.write(")");
364 }
365 self.write(&format!(" else break :{blk} "));
366 if same_type {
367 self.write(&format!("_lv_{id}"));
368 } else {
369 self.write(&format!("JsAny.from(_lv_{id})"));
370 }
371 }
372 crate::zigir::ops::LogicalOp::Or => {
373 self.write("if (js_runtime.isTruthy(_lv_");
375 self.write(&format!("{id}))"));
376 self.write(&format!(" break :{blk} "));
377 if same_type {
378 self.write(&format!("_lv_{id}"));
379 } else {
380 self.write(&format!("JsAny.from(_lv_{id})"));
381 }
382 self.write(&format!(" else break :{blk} "));
383 if same_type {
384 self.emit_expr(right);
385 } else {
386 self.write("JsAny.from(");
387 self.emit_expr(right);
388 self.write(")");
389 }
390 }
391 crate::zigir::ops::LogicalOp::Nullish => {
392 self.write(&format!("if (!_lv_{id}.isNullish())"));
394 self.write(&format!(" break :{blk} "));
395 if same_type {
396 self.write(&format!("_lv_{id}"));
397 } else {
398 self.write(&format!("JsAny.from(_lv_{id})"));
399 }
400 self.write(&format!(" else break :{blk} "));
401 if same_type {
402 self.emit_expr(right);
403 } else {
404 self.write("JsAny.from(");
405 self.emit_expr(right);
406 self.write(")");
407 }
408 }
409 }
410 self.write("; })");
411 }
412
413 crate::zigir::types::IrExpr::Update {
414 op,
415 target,
416 is_expr_stmt,
417 } => {
418 if *is_expr_stmt {
419 self.emit_assign_target_inner(target);
421 self.write(&format!(" {}", update_op_to_zig(*op)));
422 } else {
423 self.write("(");
425 self.emit_assign_target_inner(target);
426 self.write(&format!(" {}", update_op_to_zig(*op)));
427 self.write(")");
428 }
429 }
430
431 crate::zigir::types::IrExpr::Assign { op, target, value } => {
432 self.emit_compound_assign(target, *op, value);
433 }
434
435 crate::zigir::types::IrExpr::Call(call) => {
437 self.emit_call_expr(call);
438 }
439
440 crate::zigir::types::IrExpr::BuiltinCall(bc) => {
441 self.emit_builtin_call(bc);
442 }
443
444 crate::zigir::types::IrExpr::HostCall(hc) => {
445 self.write(&format!("host.{}", hc.name));
446 self.emit_args(&hc.args);
447 }
448
449 crate::zigir::types::IrExpr::FieldAccess {
451 object,
452 field,
453 field_kind,
454 } => {
455 self.emit_field_access(object, field, field_kind);
456 }
457
458 crate::zigir::types::IrExpr::IndexAccess {
459 object,
460 index,
461 index_kind,
462 } => {
463 self.emit_index_access(object, index, index_kind);
464 }
465
466 crate::zigir::types::IrExpr::ComputedField {
467 object,
468 key,
469 key_kind,
470 } => {
471 self.emit_computed_field(object, key, key_kind);
472 }
473
474 crate::zigir::types::IrExpr::ArrayLiteral(arr) => {
476 self.emit_array_literal(arr);
477 }
478
479 crate::zigir::types::IrExpr::ObjectLiteral(obj) => {
480 self.emit_object_literal(obj);
481 }
482
483 crate::zigir::types::IrExpr::ArrowFn(_arrow) => {
487 self.write("/* ArrowFn — should be lowered to closure struct */");
489 }
490
491 crate::zigir::types::IrExpr::Closure(closure) => {
492 self.write(&closure.struct_name.zig_name);
494 self.write("{ ");
495 for (i, cap) in closure.captured.iter().enumerate() {
496 if i > 0 {
497 self.write(", ");
498 }
499 if cap.is_mut {
500 self.write(&format!(".{} = &{}", cap.name.zig_name, cap.name.zig_name));
501 } else {
502 self.write(&format!(".{} = {}", cap.name.zig_name, cap.name.zig_name));
503 }
504 }
505 self.write(" }");
506 }
507
508 crate::zigir::types::IrExpr::FnExpr(fn_expr) => {
509 let name = fn_expr
511 .name
512 .as_ref()
513 .map(|n| n.zig_name.clone())
514 .unwrap_or_else(|| "_fn_expr".to_string());
515 self.write(&name);
516 }
517
518 crate::zigir::types::IrExpr::Conditional { cond, then, else_ } => {
520 self.write("if (");
521 self.emit_expr_as_bool(cond);
522 self.write(") ");
523 self.emit_expr(then);
524 self.write(" else ");
525 self.emit_expr(else_);
526 }
527
528 crate::zigir::types::IrExpr::TemplateLiteral {
529 parts,
530 exprs,
531 format_specs,
532 } => {
533 self.emit_template_literal(parts, exprs, format_specs);
534 }
535
536 crate::zigir::types::IrExpr::Await(await_expr) => {
538 self.write(&format!("({}: {{\n", await_expr.block_label));
540 self.indent_push();
541 self.write_indent();
542 self.write(&format!("var {} = io.async(", await_expr.task_var.zig_name));
543
544 if await_expr.is_host_async {
545 if let crate::zigir::types::IrExpr::Ident(id) = &*await_expr.callee {
547 self.write(&format!("host.{}_async", id.zig_name));
548 } else {
549 self.emit_expr(&await_expr.callee);
551 }
552 } else {
553 self.emit_expr(&await_expr.callee);
554 }
555
556 self.write(", .{ io");
557 for arg in &await_expr.args {
558 self.write(", ");
559 self.emit_expr(arg);
560 }
561 self.write(" });\n");
562
563 self.write_indent();
564 self.write(&format!(
565 "defer _ = {}.cancel(io) catch undefined;\n",
566 await_expr.task_var.zig_name
567 ));
568
569 self.write_indent();
570 self.write(&format!(
571 "break :{} try {}.await(io);\n",
572 await_expr.block_label, await_expr.task_var.zig_name
573 ));
574
575 self.indent_pop();
576 self.write_indent();
577 self.write("})");
578 }
579
580 crate::zigir::types::IrExpr::New(new_expr) => {
582 self.emit_new_expr(new_expr);
583 }
584
585 crate::zigir::types::IrExpr::AllocPrint { fmt, args } => {
587 if args.is_empty() {
588 let unescaped = fmt.replace("{{", "{").replace("}}", "}");
590 self.write(&format!("\"{}\"", unescaped));
591 } else {
592 self.emit_alloc_print(fmt, args);
594 }
595 }
596
597 crate::zigir::types::IrExpr::BlockExpr {
599 label,
600 body,
601 result,
602 } => {
603 self.write(&format!("({}: {{", label));
604 for stmt in body {
605 self.emit_stmt(stmt);
606 }
607 self.write("break :");
608 self.write(label);
609 self.write(" ");
610 self.emit_expr(result);
611 self.write("}})");
612 }
613
614 crate::zigir::types::IrExpr::Spread(inner) => {
616 self.emit_expr(inner);
617 }
618
619 crate::zigir::types::IrExpr::Typeof(inner) => {
620 self.write("js_runtime.jsTypeof(");
624 self.emit_expr(inner);
625 self.write(")");
626 }
627
628 crate::zigir::types::IrExpr::Void(inner) => {
629 let label = self.next_label();
632 self.write(&format!("{}: {{ _ = ", label));
633 self.emit_expr(inner);
634 self.write(&format!("; break :{} JsAny.fromUndefined(); }}", label));
635 }
636
637 crate::zigir::types::IrExpr::Paren(inner) => {
638 self.write("(");
639 self.emit_expr(inner);
640 self.write(")");
641 }
642
643 crate::zigir::types::IrExpr::Sequence(exprs) => {
644 for (i, e) in exprs.iter().enumerate() {
645 if i > 0 {
646 self.write(", ");
647 }
648 self.emit_expr(e);
649 }
650 }
651
652 crate::zigir::types::IrExpr::ArrayCallbackInline(inline_data) => {
653 self.emit_array_callback_inline(inline_data);
654 }
655
656 crate::zigir::types::IrExpr::ArrayMethodInline(inline_data) => {
657 self.emit_array_method_inline(inline_data);
658 }
659
660 crate::zigir::types::IrExpr::OptionalChain {
661 object,
662 capture_var,
663 body,
664 needs_null_check,
665 } => {
666 if *needs_null_check {
667 self.write("(if (");
668 self.emit_expr(object);
669 self.write(") |");
670 self.write(capture_var);
671 self.write("| ");
672 self.emit_expr(body);
673 self.write(" else null)");
674 } else {
675 self.emit_expr(body);
676 }
677 }
678
679 crate::zigir::types::IrExpr::CompileError { span, msg } => {
680 let loc = format!("{}:{}", span.js_line, span.js_col);
681 self.write(&emit_helpers::compile_error(&format!(
682 "{} (at {})",
683 msg, loc
684 )));
685 }
686 }
687 }
688
689 pub(crate) fn expr_to_string(&mut self, expr: &crate::zigir::types::IrExpr) -> String {
692 let saved_output = std::mem::take(&mut self.output);
693 self.emit_expr(expr);
694 let result = std::mem::take(&mut self.output);
695 self.output = saved_output;
696 result
697 }
698
699 pub(super) fn emit_assign_target_inner(
702 &mut self,
703 target: &crate::zigir::types::IrAssignTarget,
704 ) {
705 match target {
706 crate::zigir::types::IrAssignTarget::Ident(ident) => {
707 self.write(&ident.zig_name);
708 }
709 crate::zigir::types::IrAssignTarget::Member {
710 object,
711 field,
712 is_pointer,
713 field_kind,
714 } => {
715 use crate::zigir::kinds::FieldKind;
716 match field_kind {
717 FieldKind::StaticField { class_name } => {
718 self.emit_static_field(class_name, field);
719 }
720 _ => {
721 self.emit_expr(object);
722 if *is_pointer {
723 self.write(&format!(".{}.*", field));
724 } else {
725 self.write(&format!(".{}", field));
726 }
727 }
728 }
729 }
730 crate::zigir::types::IrAssignTarget::Index {
731 object,
732 index,
733 index_kind,
734 } => {
735 use crate::zigir::kinds::IndexKind;
736 match index_kind {
737 IndexKind::ArrayListItem => {
738 self.emit_arraylist_item(object, index);
739 }
740 IndexKind::SliceIndex => {
741 self.emit_slice_index(object, index);
742 }
743 }
744 }
745 crate::zigir::types::IrAssignTarget::Destructure(bindings) => {
746 for (i, binding) in bindings.iter().enumerate() {
747 if i > 0 {
748 self.write("; ");
749 }
750 self.write(&binding.pattern.zig_name);
751 if let Some(default) = &binding.default {
752 self.write(" orelse ");
753 self.emit_expr(default);
754 }
755 }
756 }
757 crate::zigir::types::IrAssignTarget::CompileError { msg } => {
758 self.write(&format!("@compileError(\"{}\")", msg));
759 }
760 }
761 }
762
763 pub(super) fn emit_compound_assign(
766 &mut self,
767 target: &crate::zigir::types::IrAssignTarget,
768 op: crate::zigir::ops::AssignOp,
769 value: &crate::zigir::types::IrExpr,
770 ) {
771 use crate::zigir::ops::AssignOp;
772 if op == AssignOp::Mod {
773 self.emit_assign_target_inner(target);
775 self.write(" = @rem(");
776 self.emit_assign_target_inner(target);
777 self.write(", ");
778 self.emit_expr(value);
779 self.write(")");
780 } else if op == AssignOp::Div {
781 self.emit_assign_target_inner(target);
783 self.write(" = @divTrunc(");
784 self.emit_assign_target_inner(target);
785 self.write(", ");
786 self.emit_expr(value);
787 self.write(")");
788 } else if op == AssignOp::LogicAnd {
789 self.emit_assign_target_inner(target);
791 self.write(" = if (");
792 self.emit_assign_target_inner(target);
793 self.write(".toBool()) ");
794 self.emit_expr(value);
795 self.write(" else ");
796 self.emit_assign_target_inner(target);
797 } else if op == AssignOp::LogicOr {
798 self.emit_assign_target_inner(target);
800 self.write(" = if (!");
801 self.emit_assign_target_inner(target);
802 self.write(".toBool()) ");
803 self.emit_expr(value);
804 self.write(" else ");
805 self.emit_assign_target_inner(target);
806 } else if op == AssignOp::Nullish {
807 self.emit_assign_target_inner(target);
809 self.write(" = if (");
810 self.emit_assign_target_inner(target);
811 self.write(".isNullish()) ");
812 self.emit_expr(value);
813 self.write(" else ");
814 self.emit_assign_target_inner(target);
815 } else {
816 self.emit_assign_target_inner(target);
817 self.write(&format!(" {} ", op.to_zig_str()));
818 self.emit_expr(value);
819 }
820 }
821
822 pub(super) fn emit_alloc_print(&mut self, fmt: &str, args: &[crate::zigir::types::IrExpr]) {
825 let arg_strs: Vec<String> = args.iter().map(|arg| self.expr_to_string(arg)).collect();
826 let args_str = format!(".{{{}}}", arg_strs.join(", "));
827 self.write(&format!(
828 "std.fmt.allocPrint(js_allocator.allocator(), \"{}\", {}) catch @panic(\"OOM: template literal allocPrint\")",
829 fmt, args_str
830 ));
831 }
832
833 pub(super) fn emit_args(&mut self, args: &[crate::zigir::types::IrExpr]) {
834 self.write("(");
835 for (i, arg) in args.iter().enumerate() {
836 if i > 0 {
837 self.write(", ");
838 }
839 if let crate::zigir::types::IrExpr::Spread(inner) = arg {
841 self.emit_expr(inner);
842 self.write(".items");
843 } else {
844 self.emit_expr(arg);
845 }
846 }
847 self.write(")");
848 }
849
850 pub(super) fn ir_expr_is_bool(expr: &crate::zigir::types::IrExpr) -> bool {
852 use crate::zigir::ops::BinOp;
853 use crate::zigir::types::IrExpr;
854
855 match expr {
856 IrExpr::BoolLiteral(_) => true,
857 IrExpr::Logical { .. } => false,
860 IrExpr::Unary {
861 op: crate::zigir::ops::UnaOp::Not,
862 ..
863 } => true,
864 IrExpr::Binary { op, .. } => matches!(
865 op,
866 BinOp::Eq
867 | BinOp::Ne
868 | BinOp::StrictEq
869 | BinOp::StrictNe
870 | BinOp::Lt
871 | BinOp::Le
872 | BinOp::Gt
873 | BinOp::Ge
874 | BinOp::In
875 | BinOp::InstanceOf
876 ),
877 _ => false,
878 }
879 }
880
881 pub(crate) fn emit_expr_as_bool(&mut self, expr: &crate::zigir::types::IrExpr) {
887 if Self::ir_expr_is_bool(expr) {
888 self.emit_expr(expr);
889 } else {
890 self.write("js_runtime.isTruthy(");
891 self.emit_expr(expr);
892 self.write(")");
893 }
894 }
895}
896
897pub(super) fn typed_array_init(
900 kind: &crate::zigir::kinds::TypedArrayKind,
901) -> (&'static str, &'static str) {
902 use crate::zigir::kinds::TypedArrayKind;
903 match kind {
904 TypedArrayKind::Int8Array => ("js_runtime.js_typedarray", "fromI64AsI8"),
905 TypedArrayKind::Uint8Array => ("js_runtime.js_typedarray", "fromI64AsU8"),
906 TypedArrayKind::Uint8ClampedArray => ("js_runtime.js_typedarray", "fromI64AsU8"),
907 TypedArrayKind::Int16Array => ("js_runtime.js_typedarray", "fromI64AsI16"),
908 TypedArrayKind::Uint16Array => ("js_runtime.js_typedarray", "fromI64AsU16"),
909 TypedArrayKind::Int32Array => ("js_runtime.js_typedarray", "fromI64AsI32"),
910 TypedArrayKind::Uint32Array => ("js_runtime.js_typedarray", "fromI64AsU32"),
911 TypedArrayKind::Float32Array => ("js_runtime.js_typedarray", "fromF64AsF32"),
912 TypedArrayKind::Float64Array => ("js_runtime.js_typedarray", "fromF64"),
913 TypedArrayKind::BigInt64Array => ("js_runtime.js_typedarray", "fromI64AsI64"),
914 TypedArrayKind::BigUint64Array => ("js_runtime.js_typedarray", "fromI64AsU64"),
915 }
916}