Skip to content

cli-support: Remove Node.js specific passStringToWasm #2310

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

Merged
merged 1 commit into from
Sep 15, 2020
Merged
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
35 changes: 0 additions & 35 deletions crates/cli-support/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,37 +1003,6 @@ impl<'a> Context<'a> {
""
};

// If we are targeting Node.js, it doesn't have `encodeInto` yet
// but it does have `Buffer::write` which has similar semantics but
// doesn't require creating intermediate view using `subarray`
// and also has `Buffer::byteLength` to calculate size upfront.
if self.config.mode.nodejs() {
let get_buf = self.expose_node_buffer_memory(memory);
let ret = MemView {
name: "passStringToWasm",
num: get_buf.num,
};
if !self.should_write_global(ret.to_string()) {
return Ok(ret);
}

self.global(&format!(
"
function {}(arg, malloc) {{
{}
const len = Buffer.byteLength(arg);
const ptr = malloc(len);
{}().write(arg, ptr, len);
WASM_VECTOR_LEN = len;
return ptr;
}}
",
ret, debug, get_buf,
));

return Ok(ret);
}

let mem = self.expose_uint8_memory(memory);
let ret = MemView {
name: "passStringToWasm",
Expand Down Expand Up @@ -1532,10 +1501,6 @@ impl<'a> Context<'a> {
return ret;
}

fn expose_node_buffer_memory(&mut self, memory: MemoryId) -> MemView {
self.memview("getNodeBufferMemory", "Buffer.from", memory)
}

fn expose_int8_memory(&mut self, memory: MemoryId) -> MemView {
self.memview("getInt8Memory", "new Int8Array", memory)
}
Expand Down