Skip to content

Commit ada15e3

Browse files
Add test to kill improper object protection
1 parent 9aef510 commit ada15e3

File tree

1 file changed

+21
-0
lines changed
  • packages/npm-packages/ruby-wasm-wasi/test

1 file changed

+21
-0
lines changed

packages/npm-packages/ruby-wasm-wasi/test/vm.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,25 @@ eval:6:in \`bar'
149149
eval:3:in \`foo'
150150
eval:11:in \`<main>'`);
151151
});
152+
153+
test("protect objects having same hash values from GC", async () => {
154+
const vm = await initRubyVM();
155+
vm.eval(`
156+
class X
157+
def hash
158+
42
159+
end
160+
def eql?(other)
161+
true
162+
end
163+
end
164+
`);
165+
166+
const o1 = vm.eval(`X.new`);
167+
const o2 = vm.eval(`X.new`);
168+
const o3 = vm.eval(`X.new`);
169+
vm.eval(`GC.start`);
170+
expect(o1.call("hash").toString()).toBe(o2.call("hash").toString());
171+
expect(o2.call("hash").toString()).toBe(o3.call("hash").toString());
172+
});
152173
});

0 commit comments

Comments
 (0)