Skip to content

Commit

Permalink
Fix primitive slice js (#722)
Browse files Browse the repository at this point in the history
* fix-primitive-slice-js

* remove bench code

* gen example js

* fix primitive slice test

* Update feature_tests/js/test/slices.mjs

Co-authored-by: Tyler K <[email protected]>

---------

Co-authored-by: Manish Goregaokar <[email protected]>
Co-authored-by: Tyler K <[email protected]>
  • Loading branch information
3 people authored Nov 5, 2024
1 parent 4f21266 commit 7a2fbdc
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion example/js/lib/api/diplomat-runtime.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions feature_tests/js/api/Float64Vec.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/js/api/diplomat-runtime.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions feature_tests/js/test/slices-ts.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import { MyString } from "diplomat-wasm-js-feature-tests";
import test from "ava";
import { MyString, Float64Vec } from "diplomat-wasm-js-feature-tests";
test("MyString functionality", (t) => {
let str = MyString.new_("This is a test value.");
t.is(str.str, "This is a test value.");
Expand All @@ -8,3 +8,8 @@ test("String List", (t) => {
let str = MyString.newFromFirst(["This", "is", "a", "test."]);
t.is(str.str, "This");
});
test("Float64Vec", (t) => {
let input = [1, 2, 3, 4, 5];
let data = Float64Vec.newIsize(input);
t.deepEqual(data.borrow(), input);
});
21 changes: 14 additions & 7 deletions feature_tests/js/test/slices-ts.mts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import test from 'ava';
import { MyString } from "diplomat-wasm-js-feature-tests";
import test from "ava";
import { MyString, Float64Vec } from "diplomat-wasm-js-feature-tests";
import wasm from "../api/diplomat-wasm.mjs";

test("MyString functionality", (t) => {
let str = MyString.new_("This is a test value.");
t.is(str.str, "This is a test value.");
let str = MyString.new_("This is a test value.");
t.is(str.str, "This is a test value.");
});

test("String List", (t) => {
let str = MyString.newFromFirst(["This", "is", "a", "test."]);
t.is(str.str, "This");
});
let str = MyString.newFromFirst(["This", "is", "a", "test."]);
t.is(str.str, "This");
});

test("Float64Vec", (t) => {
let input = [1, 2, 3, 4, 5];
let data = Float64Vec.newIsize(input);
t.deepEqual(data.borrow(), input);
});
10 changes: 8 additions & 2 deletions feature_tests/js/test/slices.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import { MyString } from "diplomat-wasm-js-feature-tests";
import { MyString, Float64Vec} from "diplomat-wasm-js-feature-tests";

test("MyString functionality", (t) => {
let str = MyString.new_("This is a test value.");
Expand All @@ -9,4 +9,10 @@ test("MyString functionality", (t) => {
test("String List", (t) => {
let str = MyString.newFromFirst(["This", "is", "a", "test."]);
t.is(str.str, "This");
});
});

test("Float64Vec", (t) => {
let input = [1, 2, 3, 4, 5];
let data = Float64Vec.newIsize(input);
t.deepEqual(data.borrow(), input);
});
2 changes: 1 addition & 1 deletion tool/src/js/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl<'jsctx, 'tcx> TyGenContext<'jsctx, 'tcx> {
// Slices are always returned to us by way of pointers, so we assume that we can just access DiplomatReceiveBuf's helper functions:
match slice {
hir::Slice::Primitive(_, primitive_type) => format!(
r#"new diplomatRuntime.DiplomatSlicePrimitive.getSlice(wasm, {variable_name}, "{}", {edges})"#,
r#"Array.from(new diplomatRuntime.DiplomatSlicePrimitive(wasm, {variable_name}, "{}", {edges}).getValue())"#,
self.formatter.fmt_primitive_list_view(primitive_type)
)
.into(),
Expand Down
2 changes: 1 addition & 1 deletion tool/templates/js/runtime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -606,4 +606,4 @@ export class GarbageCollectorGrip {
}
}

const DiplomatBufferFinalizer = new FinalizationRegistry(free => free());
const DiplomatBufferFinalizer = new FinalizationRegistry(free => free());

0 comments on commit 7a2fbdc

Please sign in to comment.