Skip to content

Commit

Permalink
feat: support Deno 1.23.x (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
zifeo authored Jul 17, 2022
1 parent 859d618 commit 3d9f15c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

- uses: denoland/setup-deno@v1
with:
deno-version: 1.18.2
deno-version: 1.23.2

- name: Install rust
uses: hecrj/setup-rust-action@v1
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target/
example/Cargo.lock
bindings.json
bindings.json
.DS_Store
10 changes: 5 additions & 5 deletions codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ const Type: Record<string, string> = {
u16: "number",
i32: "number",
u32: "number",
i64: "number",
u64: "number",
usize: "number",
isize: "number",
i64: "bigint",
u64: "bigint",
usize: "bigint",
isize: "bigint",
f32: "number",
f64: "number",
};
Expand Down Expand Up @@ -135,7 +135,7 @@ function decode(v: Uint8Array): string {
return new TextDecoder().decode(v);
}
function readPointer(v: any): Uint8Array {
const ptr = new Deno.UnsafePointerView(v as Deno.UnsafePointer)
const ptr = new Deno.UnsafePointerView(v as bigint)
const lengthBe = new Uint8Array(4);
const view = new DataView(lengthBe.buffer);
ptr.copyInto(lengthBe, 0);
Expand Down
46 changes: 23 additions & 23 deletions example/bindings/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function decode(v: Uint8Array): string {
return new TextDecoder().decode(v)
}
function readPointer(v: any): Uint8Array {
const ptr = new Deno.UnsafePointerView(v as Deno.UnsafePointer)
const ptr = new Deno.UnsafePointerView(v as bigint)
const lengthBe = new Uint8Array(4)
const view = new DataView(lengthBe.buffer)
ptr.copyInto(lengthBe, 0)
Expand Down Expand Up @@ -91,8 +91,26 @@ const _lib = await prepare(opts, {
nonblocking: false,
},
})
export type TestLifetimes = {
text: string
export type WithRecord = {
my_map: Record<string, string>
}
export type TagAndContent =
| { key: "A"; value: { b: number } }
| { key: "C"; value: { d: number } }
export type TestReservedField = {
type: number
ref: number
}
export type TestLifetimeEnums = {
Text: {
_text: string
}
}
export type OptionStruct = {
maybe: string | undefined | null
}
export type MyStruct = {
arr: Array<string>
}
/**
* Doc comment for `Input` struct.
Expand All @@ -107,18 +125,8 @@ export type Input = {
a: number
b: number
}
export type TagAndContent =
| { key: "A"; value: { b: number } }
| { key: "C"; value: { d: number } }
export type WithRecord = {
my_map: Record<string, string>
}
export type TestReservedField = {
type: number
ref: number
}
export type MyStruct = {
arr: Array<string>
export type TestLifetimes = {
text: string
}
export type TestLifetimeWrap = {
_a: TestLifetimeEnums
Expand All @@ -131,14 +139,6 @@ export type PlainEnum =
}
| "b"
| "c"
export type TestLifetimeEnums = {
Text: {
_text: string
}
}
export type OptionStruct = {
maybe: string | undefined | null
}
export function add(a0: number, a1: number) {
let rawResult = _lib.symbols.add(a0, a1)
const result = rawResult
Expand Down
2 changes: 1 addition & 1 deletion example/bindings_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Deno.test({
name: "test_lifetime_struct#test",
fn: () => {
const TEXT = "Hello, World!";
assertEquals(test_lifetime({ text: TEXT }), TEXT.length);
assertEquals(test_lifetime({ text: TEXT }), BigInt(TEXT.length));
},
});

Expand Down

0 comments on commit 3d9f15c

Please sign in to comment.