-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Create the web-sys
crate mechanically from WebIDL
#409
Merged
Merged
Changes from 14 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
0b3c2c3
Create a new `web-sys` crate
fitzgen 248d233
ci: Test the new `web-sys` crate in CI
fitzgen f591478
web-sys: Add a small README
fitzgen 40239d3
web-sys: Vendor all the WebIDL files from mozilla-central
fitzgen 6d26828
backend: Add a pass to remove AST items that use undefined imports
fitzgen 8005a89
webidl: Add a bunch of missing semicolons
fitzgen c55e1c5
webidl: Make parsing private
fitzgen 2d552a1
webidl: Remove uses of undefined import types
fitzgen d432b5b
test-project-builder: Add more profiling timers
fitzgen 43a740a
test-project-builder: Detect when webpack-dev-server fails
fitzgen af2aa4f
webidl: Specify version for dev-dependency on wasm-bindgen-backend
fitzgen 71ec407
test-project-builder: Build projects in "very verbose" mode
fitzgen efee676
guide: Add section about contributing to `web-sys`
fitzgen 13c93c4
WIP enable Event.webidl
fitzgen 6c3ed64
Update expected webidl output
alexcrichton 5f671f8
Start out a test's status as incomplete
alexcrichton 455c102
Fix onerror function in headless mode
alexcrichton a79dd3c
Fix package.json/node_modules handling in project generation
alexcrichton 94529ae
Avoid logging body text
alexcrichton b4f0fb5
Fix a relative path
alexcrichton cff9559
More expected test fixes
alexcrichton ecf6bdd
Fix a typo
alexcrichton 384a983
Merge remote-tracking branch 'origin/master' into web-sys
alexcrichton c43d740
Merge remote-tracking branch 'rustwasm/master' into web-sys
fitzgen 3266ced
test-project-builder: Allow asynchronous tests
fitzgen 16ea94c
webidl: Convert [Unforgeable] attributes into `#[wasm_bindgen(structu…
fitzgen 4040020
test-project-builder: Print generated WebIDL bindings for debugging p…
fitzgen 882183b
When we can't find a descriptor, say which one can't be found
fitzgen 126207d
web-sys: Test bindings for Event
fitzgen c992343
ci: Use `--manifest-path dir` instead of `cd dir && ...`
fitzgen 68478c6
web-sys: Just move .webidl files isntead of symlinking to enable them
fitzgen 5d7fdea
Merge remote-tracking branch 'rustwasm/master' into web-sys
fitzgen 6bfeab5
tests: Polyfill Array.prototype.values for older browsers in CI
fitzgen bc06137
test-project-builder: Don't panic on poisoned headless test mutex
fitzgen f7bb74d
JsValue: Add {is,as}_{object,function} methods
fitzgen ae3b610
tidy: Fix whitespace and missing semicolons
fitzgen 05d9eb8
Allow for dynamic feature detection of methods
fitzgen 834bfad
tests: Do feature detection in Array.prototype.values test
fitzgen 8bc01f4
Merge remote-tracking branch 'rustwasm/master' into web-sys
fitzgen 4076f4f
Add JsValue::{is_string, as_js_string} methods
fitzgen eeebca9
eslint: allow backtick string literals
fitzgen 0a5a50b
Only generate a fallback import function for non-structural imports
fitzgen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,256 @@ | ||
use ast; | ||
use proc_macro2::Ident; | ||
use syn; | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub enum ImportedTypeKind { | ||
/// The definition of an imported type. | ||
Definition, | ||
/// A reference to an imported type. | ||
Reference, | ||
} | ||
|
||
/// Iterate over definitions of and references to imported types in the AST. | ||
pub trait ImportedTypes { | ||
fn imported_types<F>(&self, f: &mut F) | ||
where | ||
F: FnMut(&Ident, ImportedTypeKind); | ||
} | ||
|
||
/// Iterate over definitions of imported types in the AST. | ||
pub trait ImportedTypeDefinitions { | ||
fn imported_type_definitions<F>(&self, f: &mut F) | ||
where | ||
F: FnMut(&Ident); | ||
} | ||
|
||
impl<T> ImportedTypeDefinitions for T | ||
where | ||
T: ImportedTypes, | ||
{ | ||
fn imported_type_definitions<F>(&self, f: &mut F) | ||
where | ||
F: FnMut(&Ident), | ||
{ | ||
self.imported_types(&mut |id, kind| { | ||
if let ImportedTypeKind::Definition = kind { | ||
f(id); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
/// Iterate over references to imported types in the AST. | ||
pub trait ImportedTypeReferences { | ||
fn imported_type_references<F>(&self, f: &mut F) | ||
where | ||
F: FnMut(&Ident); | ||
} | ||
|
||
impl<T> ImportedTypeReferences for T | ||
where | ||
T: ImportedTypes, | ||
{ | ||
fn imported_type_references<F>(&self, f: &mut F) | ||
where | ||
F: FnMut(&Ident), | ||
{ | ||
self.imported_types(&mut |id, kind| { | ||
if let ImportedTypeKind::Reference = kind { | ||
f(id); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
impl ImportedTypes for ast::Program { | ||
fn imported_types<F>(&self, f: &mut F) | ||
where | ||
F: FnMut(&Ident, ImportedTypeKind), | ||
{ | ||
self.imports.imported_types(f); | ||
self.type_aliases.imported_types(f); | ||
} | ||
} | ||
|
||
impl<T> ImportedTypes for Vec<T> | ||
where | ||
T: ImportedTypes, | ||
{ | ||
fn imported_types<F>(&self, f: &mut F) | ||
where | ||
F: FnMut(&Ident, ImportedTypeKind), | ||
{ | ||
for x in self { | ||
x.imported_types(f); | ||
} | ||
} | ||
} | ||
|
||
impl ImportedTypes for ast::Import { | ||
fn imported_types<F>(&self, f: &mut F) | ||
where | ||
F: FnMut(&Ident, ImportedTypeKind), | ||
{ | ||
self.kind.imported_types(f) | ||
} | ||
} | ||
|
||
impl ImportedTypes for ast::ImportKind { | ||
fn imported_types<F>(&self, f: &mut F) | ||
where | ||
F: FnMut(&Ident, ImportedTypeKind), | ||
{ | ||
match self { | ||
ast::ImportKind::Static(s) => s.imported_types(f), | ||
ast::ImportKind::Function(fun) => fun.imported_types(f), | ||
ast::ImportKind::Type(ty) => ty.imported_types(f), | ||
} | ||
} | ||
} | ||
|
||
impl ImportedTypes for ast::ImportStatic { | ||
fn imported_types<F>(&self, f: &mut F) | ||
where | ||
F: FnMut(&Ident, ImportedTypeKind), | ||
{ | ||
self.ty.imported_types(f); | ||
} | ||
} | ||
|
||
impl ImportedTypes for syn::Type { | ||
fn imported_types<F>(&self, f: &mut F) | ||
where | ||
F: FnMut(&Ident, ImportedTypeKind), | ||
{ | ||
match self { | ||
syn::Type::Reference(ref r) => r.imported_types(f), | ||
syn::Type::Path(ref p) => p.imported_types(f), | ||
_ => {} | ||
} | ||
} | ||
} | ||
|
||
impl ImportedTypes for syn::TypeReference { | ||
fn imported_types<F>(&self, f: &mut F) | ||
where | ||
F: FnMut(&Ident, ImportedTypeKind), | ||
{ | ||
self.elem.imported_types(f); | ||
} | ||
} | ||
|
||
impl ImportedTypes for syn::TypePath { | ||
fn imported_types<F>(&self, f: &mut F) | ||
where | ||
F: FnMut(&Ident, ImportedTypeKind), | ||
{ | ||
if self.qself.is_some() | ||
|| self.path.leading_colon.is_some() | ||
|| self.path.segments.len() != 1 | ||
{ | ||
return; | ||
} | ||
f( | ||
&self.path.segments.last().unwrap().value().ident, | ||
ImportedTypeKind::Reference, | ||
); | ||
} | ||
} | ||
|
||
impl ImportedTypes for ast::ImportFunction { | ||
fn imported_types<F>(&self, f: &mut F) | ||
where | ||
F: FnMut(&Ident, ImportedTypeKind), | ||
{ | ||
self.function.imported_types(f); | ||
self.kind.imported_types(f); | ||
} | ||
} | ||
|
||
impl ImportedTypes for ast::ImportFunctionKind { | ||
fn imported_types<F>(&self, f: &mut F) | ||
where | ||
F: FnMut(&Ident, ImportedTypeKind), | ||
{ | ||
match self { | ||
ast::ImportFunctionKind::Method { ty, .. } => ty.imported_types(f), | ||
ast::ImportFunctionKind::Normal => {} | ||
} | ||
} | ||
} | ||
|
||
impl ImportedTypes for ast::Function { | ||
fn imported_types<F>(&self, f: &mut F) | ||
where | ||
F: FnMut(&Ident, ImportedTypeKind), | ||
{ | ||
self.arguments.imported_types(f); | ||
if let Some(ref r) = self.ret { | ||
r.imported_types(f); | ||
} | ||
} | ||
} | ||
|
||
impl ImportedTypes for syn::ArgCaptured { | ||
fn imported_types<F>(&self, f: &mut F) | ||
where | ||
F: FnMut(&Ident, ImportedTypeKind), | ||
{ | ||
self.ty.imported_types(f); | ||
} | ||
} | ||
|
||
impl ImportedTypes for ast::ImportType { | ||
fn imported_types<F>(&self, f: &mut F) | ||
where | ||
F: FnMut(&Ident, ImportedTypeKind), | ||
{ | ||
f(&self.name, ImportedTypeKind::Definition); | ||
} | ||
} | ||
|
||
impl ImportedTypes for ast::TypeAlias { | ||
fn imported_types<F>(&self, f: &mut F) | ||
where | ||
F: FnMut(&Ident, ImportedTypeKind), | ||
{ | ||
f(&self.dest, ImportedTypeKind::Reference); | ||
} | ||
} | ||
|
||
/// Remove any methods, statics, &c, that reference types that are *not* | ||
/// defined. | ||
pub trait RemoveUndefinedImports { | ||
fn remove_undefined_imports<F>(&mut self, is_defined: &F) | ||
where | ||
F: Fn(&Ident) -> bool; | ||
} | ||
|
||
impl RemoveUndefinedImports for ast::Program { | ||
fn remove_undefined_imports<F>(&mut self, is_defined: &F) | ||
where | ||
F: Fn(&Ident) -> bool, | ||
{ | ||
self.imports.remove_undefined_imports(is_defined); | ||
self.type_aliases.remove_undefined_imports(is_defined); | ||
} | ||
} | ||
|
||
impl<T> RemoveUndefinedImports for Vec<T> | ||
where | ||
T: ImportedTypeReferences, | ||
{ | ||
fn remove_undefined_imports<F>(&mut self, is_defined: &F) | ||
where | ||
F: Fn(&Ident) -> bool, | ||
{ | ||
self.retain(|x| { | ||
let mut all_defined = true; | ||
x.imported_type_references(&mut |id| { | ||
all_defined = all_defined && is_defined(id); | ||
}); | ||
all_defined | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ extern crate wasm_bindgen_shared as shared; | |
|
||
pub mod ast; | ||
mod codegen; | ||
pub mod defined; | ||
pub mod util; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "web-sys" | ||
version = "0.1.0" | ||
authors = ["Nick Fitzgerald <fitzgen@gmail.com>"] | ||
readme = "./README.md" | ||
|
||
[build-dependencies] | ||
env_logger = "0.5.10" | ||
failure = "0.1" | ||
wasm-bindgen-webidl = { path = "../webidl", version = "=0.2.11" } | ||
|
||
[dependencies] | ||
wasm-bindgen = { path = "../..", version = "=0.2.11" } | ||
|
||
[dev-dependencies] | ||
wasm-bindgen-test-project-builder = { path = "../test-project-builder", version = '=0.2.11' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `web-sys` | ||
|
||
Raw bindings to Web APIs for projects using `wasm-bindgen`. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm personally also a fan of
cargo test --manifest-path crates/web-sys/Cargo.toml