Skip to content

Commit

Permalink
fix vtableIdx error with empty slot reserved (#127)
Browse files Browse the repository at this point in the history
* fix vtableIdx error with empty slot reserved
* add test samples

---------

Signed-off-by: Su Yihan <[email protected]>
  • Loading branch information
yviansu authored Dec 22, 2023
1 parent ba93dc3 commit 5f7a52a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
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 @@ -1950,12 +1950,12 @@ export class WASMExpressionGen {
index--;
}
/** it occupies two slots */
if (members[i].hasGetter && members[i].hasSetter) {
if (members[i].hasGetter || members[i].hasSetter) {
index++;
}
}

if (isSetter && member.hasGetter) {
if (isSetter) {
index++;
}

Expand Down
60 changes: 60 additions & 0 deletions tests/samples/class_accessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,64 @@ export function test15() {
const i3: I3 = new Z(1);
i3.ref = 2;
console.log(i3.ref);
}

class OnlySetter {
a = 1;

constructor(a: number) {
this.a = a;
this.foo();
this.bar();
}

foo() {
console.log('invoke foo');
}

set value(a: number) {
this.a = a;
}

bar() {
console.log('invoke bar');
}
}

export function testOnlySetter() {
const obj = new OnlySetter(10);
console.log(obj.a);
obj.a = 100;
console.log(obj.a);
}

class OnlyGetter {
a = 1;

constructor(a: number) {
this.a = a;
this.foo();
this.bar();
}

foo() {
console.log('invoke foo');
}


get value() : number {
return this.a;
}


bar() {
console.log('invoke bar');
}
}

export function testOnlyGetter() {
const obj = new OnlyGetter(10);
console.log(obj.value);
obj.a = 100;
console.log(obj.value);
}
10 changes: 10 additions & 0 deletions tools/validate/wamr/validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,16 @@
"name": "test15",
"args": [],
"result": "undefined\n2\n1\n1\n2"
},
{
"name": "testOnlySetter",
"args": [],
"result": "invoke foo\ninvoke bar\n10\n100"
},
{
"name": "testOnlyGetter",
"args": [],
"result": "invoke foo\ninvoke bar\n10\n100"
}
]
},
Expand Down

0 comments on commit 5f7a52a

Please sign in to comment.