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 primitive slice js #722

Merged
merged 5 commits into from
Nov 5, 2024
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
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) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails on my machine:

  slices-ts › Float64Vec

  test/slices-ts.mjs:14

   13:     let data = Float64Vec.newFromOwned(input);
   14:     t.is(data.borrow(), input);
   15: });

  Difference (- actual, + expected):

    [
  -   2.26666497653787e-308,
  +   1,
      2,
      3,
      4,
      5,
    ]

  › file://test/slices-ts.mjs:14:7

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());
Loading