File tree Expand file tree Collapse file tree 3 files changed +25
-7
lines changed Expand file tree Collapse file tree 3 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -348,15 +348,25 @@ fn (mut g JsGen) gen_builtin_type_defs() {
348
348
to_jsval: '+this'
349
349
)
350
350
}
351
- // u16 / u32 requires special handling in JavaScript to correctly represent it as an unsigned 32-bit integer.
352
- // The '>>> 0' bit operation ensures it is treated as unsigned, covering the full 0 to 2^32-1 range.
353
- // For u16, '>>> 0' combined with a mask of 0xffff limits it to the 0 to 2^16-1 range, correctly handling values as unsigned 16-bit integers.
354
- 'u16' , 'u32' {
351
+ // u16 and u32 requires special handling in JavaScript to correctly represent it.
352
+ // u16, '>>> 0' combined with a mask of 0xffff limits it to the 0 to 2^16-1 range, correctly handling values as unsigned 16-bit integers.
353
+ 'u16' {
355
354
g.gen_builtin_prototype (
356
355
typ_name: typ_name
357
356
default_value: 'new Number(0)'
358
- constructor: "this.val = Math.floor(Number(val) & ('" + typ_name +
359
- '\' === "u16" ? 0xffff : 0xffffffff)) >>> 0'
357
+ constructor: 'this.val = Math.floor(Number(val) & 0xffff) >>> 0'
358
+ value_of: 'Number(this.val)'
359
+ to_string: 'this.valueOf().toString()'
360
+ eq: 'new bool(self.valueOf() === other.valueOf())'
361
+ to_jsval: '+this'
362
+ )
363
+ }
364
+ // u32 '>>> 0' combined with a mask of 0xffffffff limits it to the 0 to 2^32-1 range, correctly handling values as unsigned 32-bit integers.
365
+ 'u32' {
366
+ g.gen_builtin_prototype (
367
+ typ_name: typ_name
368
+ default_value: 'new Number(0)'
369
+ constructor: 'this.val = Math.floor(Number(val) & 0xffffffff) >>> 0'
360
370
value_of: 'Number(this.val)'
361
371
to_string: 'this.valueOf().toString()'
362
372
eq: 'new bool(self.valueOf() === other.valueOf())'
Original file line number Diff line number Diff line change @@ -120,11 +120,19 @@ fn (mut g JsGen) gen_expr_to_string(expr ast.Expr, etype ast.Type) {
120
120
is_var_mut := expr.is_auto_deref_var ()
121
121
str_fn_name := g.get_str_fn (typ)
122
122
g.write ('${str_fn_name} (' )
123
+
123
124
if str_method_expects_ptr && ! is_ptr {
124
125
g.write ('new \$ ref(' )
125
126
}
127
+ if typ == ast.u32_ type && expr is ast.CastExpr {
128
+ g.write ('new u32(' )
129
+ }
126
130
127
131
g.expr (expr)
132
+
133
+ if typ == ast.u32_ type && expr is ast.CastExpr {
134
+ g.write (')' )
135
+ }
128
136
if (! str_method_expects_ptr && is_ptr && ! is_shared) || is_var_mut {
129
137
g.write ('.val' )
130
138
}
Original file line number Diff line number Diff line change 1
- -1
1
+ 4294967295
2
2
0
3
3
true
4
4
25600000
You can’t perform that action at this time.
0 commit comments