mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-29 13:06:06 +03:00
Deserialize less to match schema versions
Currently the entire `Program` is deserialized to match schema versions but this is likely to fail when the schema changes. Instead just deserialize the schema/version fields, compare those, and if successful go ahead and deserialize everything.
This commit is contained in:
parent
0ade4b8cac
commit
eb73e05b7a
@ -224,7 +224,7 @@ fn extract_programs(module: &mut Module) -> Vec<shared::Program> {
|
||||
((payload[3] as usize) << 24);
|
||||
let (a, b) = payload[4..].split_at(len as usize);
|
||||
payload = b;
|
||||
let p: shared::Program = match serde_json::from_slice(&a) {
|
||||
let p: shared::ProgramOnlySchema = match serde_json::from_slice(&a) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
panic!("failed to decode what looked like wasm-bindgen data: {}", e)
|
||||
@ -255,6 +255,12 @@ to open an issue at https://github.com/alexcrichton/wasm-bindgen/issues!
|
||||
",
|
||||
p.version, version);
|
||||
}
|
||||
let p: shared::Program = match serde_json::from_slice(&a) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
panic!("failed to decode what looked like wasm-bindgen data: {}", e)
|
||||
}
|
||||
};
|
||||
ret.push(p);
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,12 @@ extern crate serde_derive;
|
||||
|
||||
pub const SCHEMA_VERSION: &str = "2";
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct ProgramOnlySchema {
|
||||
pub schema_version: String,
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Program {
|
||||
pub exports: Vec<Export>,
|
||||
|
Loading…
Reference in New Issue
Block a user