Skip to content

Commit

Permalink
fix for of compiler error
Browse files Browse the repository at this point in the history
Signed-off-by: Su Yihan <[email protected]>
  • Loading branch information
yviansu committed Oct 23, 2023
1 parent 672f94d commit fb67710
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
1 change: 0 additions & 1 deletion runtime-library/libdyntype/extref/extref.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ extref_get_keys(dyn_ctx_t ctx, dyn_value_t obj)
create_wasm_string(exec_env, prop_name_list[i]);
str = dynamic_new_string(
ctx, wasm_stringref_obj_get_value(sringref_obj));
/* TODO: free stringref_obj */
#else
str = dynamic_new_string(ctx, prop_name_list[i],
strlen(prop_name_list[i]));
Expand Down
13 changes: 13 additions & 0 deletions runtime-library/libdyntype/libdyntype.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,19 @@ dyn_value_t dyntype_get_keys(dyn_ctx_t ctx, dyn_value_t obj)
dyntype_get_elem(ctx, dynamic_arr, i));
}

if (extref_arr) {
for (i = 0; i < extref_arr_len; i++) {
dyntype_release(ctx, dyntype_get_elem(ctx, extref_arr, i));
}
dyntype_release(ctx, extref_arr);
}
if (dynamic_arr) {
for (i = 0; i < dynamic_arr_len; i++) {
dyntype_release(ctx, dyntype_get_elem(ctx, dynamic_arr, i));
}
dyntype_release(ctx, dynamic_arr);
}

return total_arr;
}

Expand Down
3 changes: 3 additions & 0 deletions src/backend/binaryen/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@ export namespace FunctionalFuncs {
case binaryen.i64: {
return module.f64.convert_u.i64(expression);
}
case binaryen.f64: {
return expression;
}
}
return binaryen.none;
}
Expand Down
4 changes: 2 additions & 2 deletions src/backend/binaryen/wasm_expr_gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3637,7 +3637,7 @@ export class WASMExpressionGen {
}
case ValueTypeKind.STRING: {
const ownerRef = this.wasmExprGen(owner);
const idxRef = FunctionalFuncs.convertTypeToF64(
const idxF64Ref = FunctionalFuncs.convertTypeToF64(
this.module,
this.wasmExprGen(value.index),
);
Expand Down Expand Up @@ -3666,7 +3666,7 @@ export class WASMExpressionGen {
);
return this.module.call(
getBuiltInFuncName(BuiltinNames.stringcharAtFuncName),
[context, ownerRef, idxRef],
[context, ownerRef, idxF64Ref],
stringTypeInfo.typeRef,
);
}
Expand Down
37 changes: 37 additions & 0 deletions tests/samples/for_in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,40 @@ export function infc_obj_set_method() {
}
}
*/

class A {
a = 1;
b = 2;
}

export function extref_obj() {
const obj: any = new A();
for (const key in obj) {
const value = obj[key];
console.log(value);
obj[key] = 88;
console.log(obj[key]);
}
}

export function dynamic_obj() {
const obj: any = {a: 1, b: 2};
for (const key in obj) {
const value = obj[key];
console.log(value);
obj[key] = 88;
console.log(obj[key]);
}
}

export function mix_obj() {
const a = new A();
const obj: any = a;
obj['c'] = 3;
for (const key in obj) {
const value = obj[key];
console.log(value);
obj[key] = 88;
console.log(obj[key]);
}
}

0 comments on commit fb67710

Please sign in to comment.