Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix vtableIdx error with empty slot reserved #127

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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