Skip to content

Commit

Permalink
Fix idl_type swap
Browse files Browse the repository at this point in the history
  • Loading branch information
chinedufn committed Jan 23, 2019
1 parent 48b64f4 commit 048a22b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
3 changes: 3 additions & 0 deletions crates/web-sys/tests/wasm/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ export function new_title() {
}

export function new_webgl_rendering_context() {
const foo = document.createElement('canvas');
console.log('Does get context work? ' + foo.getContext('webgl'));

const canvas = document.createElement('canvas');
return canvas.getContext('webgl');
}
Expand Down
4 changes: 1 addition & 3 deletions crates/webidl-tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
// intentionally left blank

// QUESTION FOR REVIEWER: WHY? (I'll include this context in the comment)
// Intentionally left blank in order for Cargo to work
32 changes: 24 additions & 8 deletions crates/webidl/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use weedle::literal::{ConstValue, FloatLit, IntegerLit};

use first_pass::{FirstPassRecord, OperationData, OperationId, Signature};
use idl_type::{IdlType, ToIdlType};
// TODO: Remove.. just using this to see what idl types I need to change..
use std::io::Write;

/// For variadic operations an overload with a `js_sys::Array` argument is generated alongside with
/// `operation_name_0`, `operation_name_1`, `operation_name_2`, ..., `operation_name_n` overloads
Expand Down Expand Up @@ -434,7 +436,7 @@ impl<'src> FirstPassRecord<'src> {
signatures.push((signature, idl_args.clone()));
}

let idl_type = arg.ty.to_idl_type(self);
let mut idl_type = arg.ty.to_idl_type(self);
let idl_type = maybe_adjust(idl_type, id);
idl_args.push(idl_type);
}
Expand Down Expand Up @@ -719,16 +721,30 @@ pub fn public() -> syn::Visibility {
///
/// Here we implement a whitelist for those cases. This whitelist is currently
/// maintained by hand.
fn maybe_adjust<'a> (idl_type: IdlType<'a>, id: &'a OperationId) -> IdlType<'a> {
fn maybe_adjust<'a> (mut idl_type: IdlType<'a>, id: &'a OperationId) -> IdlType<'a> {
// let mut file = ::std::fs::OpenOptions::new().append(true).create(true).open("foo").unwrap();

match id {
// TODO: `match op` and return an adjusted idl_type if necessary
OperationId::Operation(Some(op)) => {
match *op {
// "vertexAttrib1fv" => {
// IdlType::Float32Array { immutable: true}
// }
_ => idl_type
}
"vertexAttrib1fv" => {
// TODO: Remove.. just using this to see what idl types I need to change..
// file.write(
// format!("{:#?}", idl_type).as_bytes()
// );
// file.write(r#"
// "#.as_bytes());

if let IdlType::Union(ref mut union) = idl_type {
if let IdlType::Float32Array { ref mut immutable } = union[0] {
*immutable = true;
}
}
}
_ => {}
};

return idl_type
}
_ => idl_type
}
Expand Down

0 comments on commit 048a22b

Please sign in to comment.