Skip to content

Commit 7532e6a

Browse files
Use writeAndReturnKindBits in write
1 parent d4c45b4 commit 7532e6a

File tree

3 files changed

+6
-152
lines changed

3 files changed

+6
-152
lines changed

Runtime/src/js-value.ts

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -78,60 +78,10 @@ export const write = (
7878
is_exception: boolean,
7979
memory: Memory
8080
) => {
81-
const exceptionBit = (is_exception ? 1 : 0) << 31;
82-
if (value === null) {
83-
memory.writeUint32(kind_ptr, exceptionBit | Kind.Null);
84-
return;
85-
}
86-
87-
const writeRef = (kind: Kind) => {
88-
memory.writeUint32(kind_ptr, exceptionBit | kind);
89-
memory.writeUint32(payload1_ptr, memory.retain(value));
90-
};
91-
92-
const type = typeof value;
93-
switch (type) {
94-
case "boolean": {
95-
memory.writeUint32(kind_ptr, exceptionBit | Kind.Boolean);
96-
memory.writeUint32(payload1_ptr, value ? 1 : 0);
97-
break;
98-
}
99-
case "number": {
100-
memory.writeUint32(kind_ptr, exceptionBit | Kind.Number);
101-
memory.writeFloat64(payload2_ptr, value);
102-
break;
103-
}
104-
case "string": {
105-
writeRef(Kind.String);
106-
break;
107-
}
108-
case "undefined": {
109-
memory.writeUint32(kind_ptr, exceptionBit | Kind.Undefined);
110-
break;
111-
}
112-
case "object": {
113-
writeRef(Kind.Object);
114-
break;
115-
}
116-
case "function": {
117-
writeRef(Kind.Function);
118-
break;
119-
}
120-
case "symbol": {
121-
writeRef(Kind.Symbol);
122-
break;
123-
}
124-
case "bigint": {
125-
writeRef(Kind.BigInt);
126-
break;
127-
}
128-
default:
129-
assertNever(type, `Type "${type}" is not supported yet`);
130-
}
81+
const kind = writeAndReturnKindBits(value, payload1_ptr, payload2_ptr, is_exception, memory);
82+
memory.writeUint32(kind_ptr, kind);
13183
};
13284

133-
/// This is a fast version of the above `write` function.
134-
/// Please synchronize with the above `write` function if you change either.
13585
export const writeAndReturnKindBits = (
13686
value: any,
13787
payload1_ptr: pointer,

Sources/JavaScriptKit/Runtime/index.js

Lines changed: 2 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/JavaScriptKit/Runtime/index.mjs

Lines changed: 2 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)