mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-23 09:41:33 +00:00
Introduce the wasm-bindgen-webidl frontend
This is still a work in progress. Parse WebIDL source text and convert it into wasm-bindgen AST, so that we can automatically emit bindings for the types and functions described in the WebIDL.
This commit is contained in:
59
crates/webidl/tests/all/Event.webidl
Normal file
59
crates/webidl/tests/all/Event.webidl
Normal file
@ -0,0 +1,59 @@
|
||||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* The origin of this IDL file is
|
||||
* http://www.w3.org/TR/2012/WD-dom-20120105/
|
||||
*
|
||||
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
|
||||
* liability, trademark and document use rules apply.
|
||||
*/
|
||||
|
||||
[Constructor(DOMString type, optional EventInit eventInitDict),
|
||||
Exposed=(Window,Worker,System), ProbablyShortLivingWrapper]
|
||||
interface Event {
|
||||
[Pure]
|
||||
readonly attribute DOMString type;
|
||||
[Pure]
|
||||
readonly attribute EventTarget? target;
|
||||
[Pure]
|
||||
readonly attribute EventTarget? currentTarget;
|
||||
|
||||
sequence<EventTarget> composedPath();
|
||||
|
||||
const unsigned short NONE = 0;
|
||||
const unsigned short CAPTURING_PHASE = 1;
|
||||
const unsigned short AT_TARGET = 2;
|
||||
const unsigned short BUBBLING_PHASE = 3;
|
||||
[Pure]
|
||||
readonly attribute unsigned short eventPhase;
|
||||
|
||||
void stopPropagation();
|
||||
void stopImmediatePropagation();
|
||||
|
||||
[Pure]
|
||||
readonly attribute boolean bubbles;
|
||||
[Pure]
|
||||
readonly attribute boolean cancelable;
|
||||
[NeedsCallerType]
|
||||
void preventDefault();
|
||||
[Pure, NeedsCallerType]
|
||||
readonly attribute boolean defaultPrevented;
|
||||
[ChromeOnly, Pure]
|
||||
readonly attribute boolean defaultPreventedByChrome;
|
||||
[ChromeOnly, Pure]
|
||||
readonly attribute boolean defaultPreventedByContent;
|
||||
[Pure]
|
||||
readonly attribute boolean composed;
|
||||
|
||||
[Unforgeable, Pure]
|
||||
readonly attribute boolean isTrusted;
|
||||
[Pure]
|
||||
readonly attribute DOMHighResTimeStamp timeStamp;
|
||||
|
||||
void initEvent(DOMString type,
|
||||
optional boolean bubbles = false,
|
||||
optional boolean cancelable = false);
|
||||
attribute boolean cancelBubble;
|
||||
};
|
24
crates/webidl/tests/all/event.rs
Normal file
24
crates/webidl/tests/all/event.rs
Normal file
@ -0,0 +1,24 @@
|
||||
use super::backend;
|
||||
use proc_macro2;
|
||||
use syn;
|
||||
|
||||
assert_parse!(
|
||||
event,
|
||||
include_str!("./Event.webidl"),
|
||||
backend::ast::Program {
|
||||
exports: vec![],
|
||||
imports: vec![backend::ast::Import {
|
||||
module: None,
|
||||
version: None,
|
||||
js_namespace: None,
|
||||
kind: backend::ast::ImportKind::Type(backend::ast::ImportType {
|
||||
vis: syn::Visibility::Public(syn::VisPublic {
|
||||
pub_token: syn::token::Pub(proc_macro2::Span::call_site()),
|
||||
}),
|
||||
name: syn::Ident::new("Event", proc_macro2::Span::call_site()),
|
||||
}),
|
||||
}],
|
||||
enums: vec![],
|
||||
structs: vec![],
|
||||
}
|
||||
);
|
21
crates/webidl/tests/all/lib.rs
Normal file
21
crates/webidl/tests/all/lib.rs
Normal file
@ -0,0 +1,21 @@
|
||||
extern crate proc_macro2;
|
||||
extern crate syn;
|
||||
extern crate wasm_bindgen_backend as backend;
|
||||
extern crate wasm_bindgen_webidl as wb_webidl;
|
||||
|
||||
pub fn assert_parse(webidl: &str, expected: backend::ast::Program) {
|
||||
let actual = wb_webidl::parse(webidl).expect("should parse the webidl source OK");
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
|
||||
macro_rules! assert_parse {
|
||||
($test_name:ident, $webidl_source:expr, $expected_ast:expr) => {
|
||||
#[test]
|
||||
fn $test_name() {
|
||||
$crate::assert_parse($webidl_source, $expected_ast);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
mod event;
|
||||
mod simple;
|
3
crates/webidl/tests/all/simple.rs
Normal file
3
crates/webidl/tests/all/simple.rs
Normal file
@ -0,0 +1,3 @@
|
||||
use super::backend;
|
||||
|
||||
assert_parse!(empty, "", backend::ast::Program::default());
|
Reference in New Issue
Block a user