Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into add-allow-clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
T5uku5hi committed Feb 8, 2019
2 parents fb8e158 + 812c6bf commit 1b76410
Show file tree
Hide file tree
Showing 24 changed files with 226 additions and 131 deletions.
2 changes: 1 addition & 1 deletion crates/cli-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Shared support for the wasm-bindgen-cli package, an internal dependency
[dependencies]
base64 = "0.9"
failure = "0.1.2"
parity-wasm = "0.35"
parity-wasm = "0.36"
tempfile = "3.0"
wasm-bindgen-gc = { path = '../gc', version = '=0.2.33' }
wasm-bindgen-shared = { path = "../shared", version = '=0.2.33' }
Expand Down
17 changes: 17 additions & 0 deletions crates/cli-support/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,23 @@ impl<'a> Context<'a> {
));
}

fn expose_handle_error(&mut self) {
if !self.should_write_global("handle_error") {
return;
}
self.expose_uint32_memory();
self.expose_add_heap_object();
self.global(
"
function handleError(exnptr, e) {
const view = getUint32Memory();
view[exnptr / 4] = 1;
view[exnptr / 4 + 1] = addHeapObject(e);
}
",
);
}

fn wasm_import_needed(&self, name: &str) -> bool {
let imports = match self.module.import_section() {
Some(s) => s,
Expand Down
13 changes: 3 additions & 10 deletions crates/cli-support/src/js/rust2js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,23 +643,16 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
};

if self.catch {
self.cx.expose_uint32_memory();
self.cx.expose_add_heap_object();
let catch = "\
const view = getUint32Memory();\n\
view[exnptr / 4] = 1;\n\
view[exnptr / 4 + 1] = addHeapObject(e);\n\
";

self.cx.expose_handle_error();
invoc = format!(
"\
try {{\n\
{}
}} catch (e) {{\n\
{}
handleError(exnptr, e);\n\
}}\
",
&invoc, catch
&invoc
);
} else if self.catch_and_rethrow {
invoc = format!(
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ docopt = "1.0"
env_logger = "0.6"
failure = "0.1.2"
log = "0.4"
parity-wasm = "0.35"
parity-wasm = "0.36"
rouille = { version = "3.0.0", default-features = false }
serde = "1.0"
serde_derive = "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
const orig = id => (...args) => {
const logs = document.getElementById(id);
for (let msg of args) {
logs.innerHTML += `${msg}\n`;
logs.textContent += `${msg}\n`;
}
};

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/bin/wasm-bindgen-test-runner/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn spawn(
// Now that we've gotten to the point where JS is executing, update our
// status text as at this point we should be asynchronously fetching the
// wasm module.
document.getElementById('output').innerHTML = "Loading wasm module...";
document.getElementById('output').textContent = "Loading wasm module...";
async function main(test) {{
// this is a facet of using wasm2es6js, a hack until browsers have
Expand Down
7 changes: 7 additions & 0 deletions crates/futures/tests/tests.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,10 @@ fn spawn_local_err_no_exception() -> impl Future<Item = (), Error = JsValue> {
})
}

#[wasm_bindgen_test(async)]
fn can_create_multiple_futures_from_same_promise() -> impl Future<Item = (), Error = JsValue> {
let promise = js_sys::Promise::resolve(&JsValue::null());
let a = JsFuture::from(promise.clone());
let b = JsFuture::from(promise);
futures::future::join_all(vec![a, b]).map(|_| ())
}
2 changes: 1 addition & 1 deletion crates/gc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Support for removing unused items from a wasm executable
"""

[dependencies]
parity-wasm = "0.35.1"
parity-wasm = "0.36"
log = "0.4"
rustc-demangle = "0.1.9"

Expand Down
4 changes: 4 additions & 0 deletions crates/gc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ fn run(config: &mut Config, module: &mut Module) {
info!("skipping reloc section");
continue;
}
Section::DataCount(..) => {
info!("skipping data count section");
continue;
}
Section::Type(ref mut s) => cx.remap_type_section(s),
Section::Import(ref mut s) => cx.remap_import_section(s),
Section::Function(ref mut s) => cx.remap_function_section(s),
Expand Down
18 changes: 0 additions & 18 deletions crates/gc/tests/wat/remove-passive-memory-segment.wat

This file was deleted.

29 changes: 0 additions & 29 deletions crates/gc/tests/wat/renumber-data-segment.wat

This file was deleted.

32 changes: 0 additions & 32 deletions crates/gc/tests/wat/renumber-passive-segment.wat

This file was deleted.

24 changes: 8 additions & 16 deletions crates/test/src/rt/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ extern "C" {
fn getElementById(this: &HTMLDocument, id: &str) -> Element;

type Element;
#[wasm_bindgen(method, getter = innerHTML, structural)]
fn inner_html(this: &Element) -> String;
#[wasm_bindgen(method, setter = innerHTML, structural)]
fn set_inner_html(this: &Element, html: &str);
#[wasm_bindgen(method, getter = textContent, structural)]
fn text_content(this: &Element) -> String;
#[wasm_bindgen(method, setter = textContent, structural)]
fn set_text_content(this: &Element, text: &str);

type BrowserError;
#[wasm_bindgen(method, getter, structural)]
Expand All @@ -37,24 +37,16 @@ impl Browser {
/// (requires `Node::new()` to have return `None` first).
pub fn new() -> Browser {
let pre = document.getElementById("output");
pre.set_inner_html("");
pre.set_text_content("");
Browser { pre }
}
}

impl super::Formatter for Browser {
fn writeln(&self, line: &str) {
let mut html = self.pre.inner_html();
for c in line.chars() {
match c {
'<' => html.push_str("&lt;"),
'>' => html.push_str("&gt;"),
'&' => html.push_str("&amp;"),
c => html.push(c),
}
}
html.push_str("\n");
self.pre.set_inner_html(&html);
let mut html = self.pre.text_content();
html.extend(line.chars().chain(Some('\n')));
self.pre.set_text_content(&html);
}

fn log_test(&self, name: &str, result: &Result<(), JsValue>) {
Expand Down
2 changes: 1 addition & 1 deletion crates/threads-xform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ Support for threading-related transformations in wasm-bindgen
"""

[dependencies]
parity-wasm = "0.35"
parity-wasm = "0.36"
failure = "0.1"
2 changes: 1 addition & 1 deletion crates/wasm-interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Micro-interpreter optimized for wasm-bindgen's use case
"""

[dependencies]
parity-wasm = "0.35"
parity-wasm = "0.36"

[dev-dependencies]
tempfile = "3"
5 changes: 5 additions & 0 deletions crates/web-sys/tests/wasm/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ export function new_title() {
return document.createElement("title");
}

export function new_webgl_rendering_context() {
const canvas = document.createElement('canvas');
return canvas.getContext('webgl');
}

export function new_xpath_result() {
let xmlDoc = new DOMParser().parseFromString("<root><value>tomato</value></root>", "application/xml");
let xpathResult = xmlDoc.evaluate("/root//value", xmlDoc, null, XPathResult.ANY_TYPE, null);
Expand Down
1 change: 1 addition & 0 deletions crates/web-sys/tests/wasm/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub mod style_element;
pub mod table_element;
pub mod title_element;
pub mod xpath_result;
pub mod whitelisted_immutable_slices;

#[wasm_bindgen_test]
fn deref_works() {
Expand Down
57 changes: 57 additions & 0 deletions crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//! When generating our web_sys APIs we default to setting slice references that
//! get passed to JS as mutable in case they get mutated in JS.
//!
//! In certain cases we know for sure that the slice will not get mutated - for
//! example when working with the WebGlRenderingContext APIs.
//!
//! These tests ensure that whitelisted methods do indeed accept mutable slices.
//! Especially important since this whitelist is stringly typed and currently
//! maintained by hand.
//!
//! @see https://github.com/rustwasm/wasm-bindgen/issues/1005

use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;
use web_sys::WebGlRenderingContext;

#[wasm_bindgen(module = "./tests/wasm/element.js")]
extern "C" {
fn new_webgl_rendering_context() -> WebGlRenderingContext;
// TODO: Add a function to create another type to test here.
// These functions come from element.js
}

// TODO: Uncomment WebGlRenderingContext test. Every now and then we can check if this works
// in the latest geckodriver.
//
// Currently commented out because WebGl isn't working in geckodriver.
//
// It currently works in chromedriver so if you need to run this in the meantime you can
// uncomment this block and run it in using chromedriver.
//
// CHROMEDRIVER=chromedriver cargo test --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --all-features test_webgl_rendering_context_immutable_slices

// Ensure that our whitelisted WebGlRenderingContext methods work
//#[wasm_bindgen_test]
//fn test_webgl_rendering_context_immutable_slices() {
// let gl = new_webgl_rendering_context();
//
// gl.vertex_attrib1fv_with_f32_array(0, &[1.]);
// gl.vertex_attrib2fv_with_f32_array(0, &[1.]);
// gl.vertex_attrib3fv_with_f32_array(0, &[1.]);
// gl.vertex_attrib4fv_with_f32_array(0, &[1.]);
//
// gl.uniform1fv_with_f32_array(None, &[1.]);
// gl.uniform2fv_with_f32_array(None, &[1.]);
// gl.uniform3fv_with_f32_array(None, &[1.]);
// gl.uniform4fv_with_f32_array(None, &[1.]);
//
// gl.uniform_matrix2fv_with_f32_array(None, false, &[1.]);
// gl.uniform_matrix3fv_with_f32_array(None, false, &[1.]);
// gl.uniform_matrix4fv_with_f32_array(None, false, &[1.]);
//}

// TODO:
//#[wasm_bindgen_test]
//fn test_another_types_immutable_slices_here() {
//}
2 changes: 1 addition & 1 deletion crates/webidl-tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
// intentionally left blank
// Intentionally left blank in order for Cargo to work
4 changes: 4 additions & 0 deletions crates/webidl/src/first_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub(crate) struct FirstPassRecord<'src> {
pub(crate) dictionaries: BTreeMap<&'src str, DictionaryData<'src>>,
pub(crate) callbacks: BTreeSet<&'src str>,
pub(crate) callback_interfaces: BTreeMap<&'src str, CallbackInterfaceData<'src>>,
pub(crate) immutable_f32_whitelist: BTreeSet<&'static str>
}

/// We need to collect interface data during the first pass, to be used later.
Expand Down Expand Up @@ -83,6 +84,9 @@ pub(crate) struct CallbackInterfaceData<'src> {
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Copy)]
pub(crate) enum OperationId<'src> {
Constructor(IgnoreTraits<&'src str>),
/// The name of a function in crates/web-sys/webidls/enabled/*.webidl
///
/// ex: Operation(Some("vertexAttrib1fv"))
Operation(Option<&'src str>),
IndexingGetter,
IndexingSetter,
Expand Down
Loading

0 comments on commit 1b76410

Please sign in to comment.