427 lines
14 KiB
Rust
Raw Normal View History

use std::iter::{self, FromIterator};
use backend;
use backend::util::{ident_ty, leading_colon_path_ty, raw_ident, rust_ident, simple_path_ty};
use heck::{CamelCase, SnakeCase};
use proc_macro2::Ident;
use syn;
use webidl;
2018-07-02 20:35:05 -07:00
use webidl::ast::ExtendedAttribute;
use first_pass::FirstPassRecord;
fn shared_ref(ty: syn::Type) -> syn::Type {
syn::TypeReference {
and_token: Default::default(),
lifetime: None,
mutability: None,
elem: Box::new(ty),
}.into()
}
pub fn webidl_const_ty_to_syn_ty(ty: &webidl::ast::ConstType) -> syn::Type {
use webidl::ast::ConstType::*;
// similar to webidl_ty_to_syn_ty
match ty {
Boolean => ident_ty(raw_ident("bool")),
Byte => ident_ty(raw_ident("i8")),
Octet => ident_ty(raw_ident("u8")),
RestrictedDouble | UnrestrictedDouble => ident_ty(raw_ident("f64")),
RestrictedFloat | UnrestrictedFloat => ident_ty(raw_ident("f32")),
SignedLong => ident_ty(raw_ident("i32")),
SignedLongLong => ident_ty(raw_ident("i64")),
SignedShort => ident_ty(raw_ident("i16")),
UnsignedLong => ident_ty(raw_ident("u32")),
UnsignedLongLong => ident_ty(raw_ident("u64")),
UnsignedShort => ident_ty(raw_ident("u16")),
Identifier(ref id) => ident_ty(rust_ident(id)),
}
}
pub fn webidl_const_v_to_backend_const_v(v: &webidl::ast::ConstValue) -> backend::ast::ConstValue {
match *v {
webidl::ast::ConstValue::BooleanLiteral(b) => backend::ast::ConstValue::BooleanLiteral(b),
webidl::ast::ConstValue::FloatLiteral(f) => backend::ast::ConstValue::FloatLiteral(f),
webidl::ast::ConstValue::SignedIntegerLiteral(i) => backend::ast::ConstValue::SignedIntegerLiteral(i),
webidl::ast::ConstValue::UnsignedIntegerLiteral(u) => backend::ast::ConstValue::UnsignedIntegerLiteral(u),
webidl::ast::ConstValue::Null => backend::ast::ConstValue::Null,
}
}
fn simple_fn_arg(ident: Ident, ty: syn::Type) -> syn::ArgCaptured {
syn::ArgCaptured {
pat: syn::Pat::Ident(syn::PatIdent {
by_ref: None,
mutability: None,
ident,
subpat: None,
}),
colon_token: Default::default(),
ty,
}
}
fn unit_ty() -> syn::Type {
syn::Type::Tuple(syn::TypeTuple {
paren_token: Default::default(),
elems: syn::punctuated::Punctuated::new(),
})
}
fn result_ty(t: syn::Type) -> syn::Type {
let js_value = leading_colon_path_ty(vec![rust_ident("wasm_bindgen"), rust_ident("JsValue")]);
let arguments = syn::PathArguments::AngleBracketed(syn::AngleBracketedGenericArguments {
colon2_token: None,
lt_token: Default::default(),
args: FromIterator::from_iter(vec![
syn::GenericArgument::Type(t),
syn::GenericArgument::Type(js_value),
]),
gt_token: Default::default(),
});
let ident = raw_ident("Result");
let seg = syn::PathSegment { ident, arguments };
let path: syn::Path = seg.into();
let ty = syn::TypePath { qself: None, path };
ty.into()
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum TypePosition {
Argument,
Return,
}
impl<'a> FirstPassRecord<'a> {
pub fn webidl_ty_to_syn_ty(
&self,
ty: &webidl::ast::Type,
pos: TypePosition,
) -> Option<syn::Type> {
// nullable types are not yet supported (see issue #14)
if ty.nullable {
2018-06-14 19:21:33 -07:00
return None;
}
Some(match ty.kind {
// `any` becomes `::wasm_bindgen::JsValue`.
webidl::ast::TypeKind::Any => {
simple_path_ty(vec![rust_ident("wasm_bindgen"), rust_ident("JsValue")])
}
// A reference to a type by name becomes the same thing in the
// bindings.
webidl::ast::TypeKind::Identifier(ref id) => {
let ty = ident_ty(rust_ident(id.to_camel_case().as_str()));
if self.interfaces.contains(id) {
if pos == TypePosition::Argument {
shared_ref(ty)
} else {
ty
}
} else if self.dictionaries.contains(id) {
ty
} else if self.enums.contains(id) {
ty
} else {
warn!("unrecognized type {}", id);
ty
}
}
// Scalars.
webidl::ast::TypeKind::Boolean => ident_ty(raw_ident("bool")),
webidl::ast::TypeKind::Byte => ident_ty(raw_ident("i8")),
webidl::ast::TypeKind::Octet => ident_ty(raw_ident("u8")),
webidl::ast::TypeKind::RestrictedDouble | webidl::ast::TypeKind::UnrestrictedDouble => {
ident_ty(raw_ident("f64"))
}
webidl::ast::TypeKind::RestrictedFloat | webidl::ast::TypeKind::UnrestrictedFloat => {
ident_ty(raw_ident("f32"))
}
webidl::ast::TypeKind::SignedLong => ident_ty(raw_ident("i32")),
webidl::ast::TypeKind::SignedLongLong => ident_ty(raw_ident("i64")),
webidl::ast::TypeKind::SignedShort => ident_ty(raw_ident("i16")),
webidl::ast::TypeKind::UnsignedLong => ident_ty(raw_ident("u32")),
webidl::ast::TypeKind::UnsignedLongLong => ident_ty(raw_ident("u64")),
webidl::ast::TypeKind::UnsignedShort => ident_ty(raw_ident("u16")),
// `DOMString -> `&str` for arguments
webidl::ast::TypeKind::DOMString if pos == TypePosition::Argument => {
shared_ref(ident_ty(raw_ident("str")))
}
// `DOMString` is not supported yet in other positions.
webidl::ast::TypeKind::DOMString => return None,
// Support for these types is not yet implemented, so skip
// generating any bindings for this function.
webidl::ast::TypeKind::ArrayBuffer
| webidl::ast::TypeKind::ByteString
| webidl::ast::TypeKind::DataView
| webidl::ast::TypeKind::Error
| webidl::ast::TypeKind::Float32Array
| webidl::ast::TypeKind::Float64Array
| webidl::ast::TypeKind::FrozenArray(_)
| webidl::ast::TypeKind::Int16Array
| webidl::ast::TypeKind::Int32Array
| webidl::ast::TypeKind::Int8Array
| webidl::ast::TypeKind::Object
| webidl::ast::TypeKind::Promise(_)
| webidl::ast::TypeKind::Record(..)
| webidl::ast::TypeKind::Sequence(_)
| webidl::ast::TypeKind::Symbol
| webidl::ast::TypeKind::USVString
| webidl::ast::TypeKind::Uint16Array
| webidl::ast::TypeKind::Uint32Array
| webidl::ast::TypeKind::Uint8Array
| webidl::ast::TypeKind::Uint8ClampedArray
| webidl::ast::TypeKind::Union(_) => {
return None;
}
})
}
2018-06-14 19:21:33 -07:00
fn webidl_arguments_to_syn_arg_captured<'b, I>(
&self,
arguments: I,
kind: &backend::ast::ImportFunctionKind,
) -> Option<Vec<syn::ArgCaptured>>
where
I: Iterator<Item = (&'b str, &'b webidl::ast::Type, bool)>,
{
let estimate = arguments.size_hint();
let len = estimate.1.unwrap_or(estimate.0);
let mut res = if let backend::ast::ImportFunctionKind::Method {
ty,
kind:
backend::ast::MethodKind::Operation(backend::ast::Operation {
is_static: false, ..
}),
..
} = kind
2018-06-14 19:21:33 -07:00
{
let mut res = Vec::with_capacity(len + 1);
res.push(simple_fn_arg(raw_ident("self_"), shared_ref(ty.clone())));
res
} else {
Vec::with_capacity(len)
};
for (name, ty, variadic) in arguments {
if variadic {
warn!("Variadic arguments are not supported yet",);
return None;
}
match self.webidl_ty_to_syn_ty(ty, TypePosition::Argument) {
None => {
warn!("Argument's type is not yet supported: {:?}", ty);
return None;
}
Some(ty) => res.push(simple_fn_arg(rust_ident(&name.to_snake_case()), ty)),
}
}
Some(res)
}
pub fn create_function<'b, I>(
&self,
name: &str,
arguments: I,
mut ret: Option<syn::Type>,
kind: backend::ast::ImportFunctionKind,
structural: bool,
catch: bool,
) -> Option<backend::ast::ImportFunction>
where
I: Iterator<Item = (&'b str, &'b webidl::ast::Type, bool)>,
{
let rust_name = rust_ident(&name.to_snake_case());
let name = raw_ident(name);
let arguments = self.webidl_arguments_to_syn_arg_captured(arguments, &kind)?;
let js_ret = ret.clone();
if catch {
ret = Some(ret.map_or_else(|| result_ty(unit_ty()), result_ty))
}
let shim = {
let ns = match kind {
backend::ast::ImportFunctionKind::Normal => "",
backend::ast::ImportFunctionKind::Method { ref class, .. } => class,
};
raw_ident(&format!("__widl_f_{}_{}", rust_name, ns))
};
Some(backend::ast::ImportFunction {
function: backend::ast::Function {
name,
arguments,
ret,
rust_attrs: vec![],
rust_vis: public(),
},
rust_name,
js_ret,
catch,
structural,
kind,
shim,
})
}
pub fn create_basic_method(
&self,
arguments: &[webidl::ast::Argument],
name: Option<&String>,
return_type: &webidl::ast::ReturnType,
self_name: &str,
is_static: bool,
catch: bool,
) -> Option<backend::ast::ImportFunction> {
let name = match name {
2018-06-14 19:21:33 -07:00
None => {
warn!("Operations without a name are unsupported");
return None;
}
Some(ref name) => name,
};
let kind = backend::ast::ImportFunctionKind::Method {
class: self_name.to_string(),
ty: ident_ty(rust_ident(self_name.to_camel_case().as_str())),
kind: backend::ast::MethodKind::Operation(backend::ast::Operation {
is_static,
kind: backend::ast::OperationKind::Regular,
}),
};
let ret = match return_type {
webidl::ast::ReturnType::Void => None,
webidl::ast::ReturnType::NonVoid(ty) => {
match self.webidl_ty_to_syn_ty(ty, TypePosition::Return) {
None => {
warn!("Operation's return type is not yet supported: {:?}", ty);
return None;
}
Some(ty) => Some(ty),
}
}
};
self.create_function(
&name,
arguments
.iter()
.map(|arg| (&*arg.name, &*arg.type_, arg.variadic)),
ret,
kind,
false,
catch,
)
}
pub fn create_getter(
&self,
name: &str,
ty: &webidl::ast::Type,
self_name: &str,
is_static: bool,
is_structural: bool,
catch: bool,
) -> Option<backend::ast::ImportFunction> {
let ret = match self.webidl_ty_to_syn_ty(ty, TypePosition::Return) {
None => {
warn!("Attribute's type does not yet support reading: {:?}", ty);
2018-06-14 19:21:33 -07:00
return None;
}
Some(ty) => Some(ty),
};
2018-06-14 19:21:33 -07:00
let kind = backend::ast::ImportFunctionKind::Method {
class: self_name.to_string(),
ty: ident_ty(rust_ident(self_name.to_camel_case().as_str())),
kind: backend::ast::MethodKind::Operation(backend::ast::Operation {
is_static,
kind: backend::ast::OperationKind::Getter(Some(raw_ident(name))),
}),
};
self.create_function(name, iter::empty(), ret, kind, is_structural, catch)
}
pub fn create_setter(
&self,
name: &str,
ty: &webidl::ast::Type,
self_name: &str,
is_static: bool,
is_structural: bool,
catch: bool,
) -> Option<backend::ast::ImportFunction> {
let kind = backend::ast::ImportFunctionKind::Method {
class: self_name.to_string(),
ty: ident_ty(rust_ident(self_name.to_camel_case().as_str())),
kind: backend::ast::MethodKind::Operation(backend::ast::Operation {
is_static,
kind: backend::ast::OperationKind::Setter(Some(raw_ident(name))),
}),
};
self.create_function(
&format!("set_{}", name),
iter::once((name, ty, false)),
None,
kind,
is_structural,
catch,
)
}
}
2018-07-02 20:35:05 -07:00
fn has_named_attribute(ext_attrs: &[Box<ExtendedAttribute>], attribute: &str) -> bool {
ext_attrs.iter().any(|attr| match &**attr {
ExtendedAttribute::NoArguments(webidl::ast::Other::Identifier(name)) => {
name == attribute
}
_ => false,
2018-07-02 20:35:05 -07:00
})
}
Create the `web-sys` crate mechanically from WebIDL (#409) * Create a new `web-sys` crate This will eventually contain all the WebIDL-generated bindings to Web APIs. * ci: Test the new `web-sys` crate in CI * web-sys: Add a small README * web-sys: Vendor all the WebIDL files from mozilla-central * backend: Add a pass to remove AST items that use undefined imports This is necessary for the WebIDL frontend, which can't translate many WebIDL constructs into equivalent wasm-bindgen AST things yet. It lets us make incremental progress: we can generate bindings to methods we can support right now even though there might be methods on the same interface that we can't support yet. * webidl: Add a bunch of missing semicolons * webidl: Make parsing private It was only `pub` so that we could test it, but we ended up moving towards integration tests rather than unit tests that assert particular ASTs are parsed from WebIDL files. * webidl: Remove uses of undefined import types * test-project-builder: Build projects in "very verbose" mode This helps for debugging failing WebIDL-related tests. * test-project-builder: Add more profiling timers * test-project-builder: Detect when webpack-dev-server fails Instead of going into an infinite loop, detect when webpack-dev-server fails to start up and early exit the test. * webidl: Specify version for dev-dependency on wasm-bindgen-backend Instead of only a relative path. * guide: Add section about contributing to `web-sys` * WIP enable Event.webidl Still need to fix and finish the test. * Update expected webidl output * Start out a test's status as incomplete That way if we don't fill it in the error message doesn't look quite so bizarre * Fix onerror function in headless mode Otherwise we don't see any output! * Fix package.json/node_modules handling in project generation Make sure these are looked up in the git project root rather than the crate root * Avoid logging body text This was meant for debugging and is otherwise pretty noisy * Fix a relative path * More expected test fixes * Fix a typo * test-project-builder: Allow asynchronous tests * webidl: Convert [Unforgeable] attributes into `#[wasm_bindgen(structural)]` Fixes #432 * test-project-builder: Print generated WebIDL bindings for debugging purposes Helps debug bad WebIDL bindings generation inside tests. * When we can't find a descriptor, say which one can't be found This helps when debugging things that need to become structural. * web-sys: Test bindings for Event * ci: Use `--manifest-path dir` instead of `cd dir && ...` * web-sys: Just move .webidl files isntead of symlinking to enable them * tests: Polyfill Array.prototype.values for older browsers in CI * test-project-builder: Don't panic on poisoned headless test mutex We only use it to serialize headless tests so that we don't try to bind the port concurrently. Its OK to run another headless test if an earlier one panicked. * JsValue: Add {is,as}_{object,function} methods Allows dynamically casting values to `js::Object` and `js::Function`. * tidy: Fix whitespace and missing semicolons * Allow for dynamic feature detection of methods If we create bindings to a method that doesn't exist in this implementation, then it shouldn't fail until if/when we actually try and invoke that missing method. * tests: Do feature detection in Array.prototype.values test * Add JsValue::{is_string, as_js_string} methods And document all the cast/convert/check methods for js value. * eslint: allow backtick string literals * Only generate a fallback import function for non-structural imports
2018-07-09 16:35:25 -07:00
/// ChromeOnly is for things that are only exposed to privileged code in Firefox.
pub fn is_chrome_only(ext_attrs: &[Box<ExtendedAttribute>]) -> bool {
has_named_attribute(ext_attrs, "ChromeOnly")
}
pub fn is_no_interface_object(ext_attrs: &[Box<ExtendedAttribute>]) -> bool {
has_named_attribute(ext_attrs, "NoInterfaceObject")
}
Create the `web-sys` crate mechanically from WebIDL (#409) * Create a new `web-sys` crate This will eventually contain all the WebIDL-generated bindings to Web APIs. * ci: Test the new `web-sys` crate in CI * web-sys: Add a small README * web-sys: Vendor all the WebIDL files from mozilla-central * backend: Add a pass to remove AST items that use undefined imports This is necessary for the WebIDL frontend, which can't translate many WebIDL constructs into equivalent wasm-bindgen AST things yet. It lets us make incremental progress: we can generate bindings to methods we can support right now even though there might be methods on the same interface that we can't support yet. * webidl: Add a bunch of missing semicolons * webidl: Make parsing private It was only `pub` so that we could test it, but we ended up moving towards integration tests rather than unit tests that assert particular ASTs are parsed from WebIDL files. * webidl: Remove uses of undefined import types * test-project-builder: Build projects in "very verbose" mode This helps for debugging failing WebIDL-related tests. * test-project-builder: Add more profiling timers * test-project-builder: Detect when webpack-dev-server fails Instead of going into an infinite loop, detect when webpack-dev-server fails to start up and early exit the test. * webidl: Specify version for dev-dependency on wasm-bindgen-backend Instead of only a relative path. * guide: Add section about contributing to `web-sys` * WIP enable Event.webidl Still need to fix and finish the test. * Update expected webidl output * Start out a test's status as incomplete That way if we don't fill it in the error message doesn't look quite so bizarre * Fix onerror function in headless mode Otherwise we don't see any output! * Fix package.json/node_modules handling in project generation Make sure these are looked up in the git project root rather than the crate root * Avoid logging body text This was meant for debugging and is otherwise pretty noisy * Fix a relative path * More expected test fixes * Fix a typo * test-project-builder: Allow asynchronous tests * webidl: Convert [Unforgeable] attributes into `#[wasm_bindgen(structural)]` Fixes #432 * test-project-builder: Print generated WebIDL bindings for debugging purposes Helps debug bad WebIDL bindings generation inside tests. * When we can't find a descriptor, say which one can't be found This helps when debugging things that need to become structural. * web-sys: Test bindings for Event * ci: Use `--manifest-path dir` instead of `cd dir && ...` * web-sys: Just move .webidl files isntead of symlinking to enable them * tests: Polyfill Array.prototype.values for older browsers in CI * test-project-builder: Don't panic on poisoned headless test mutex We only use it to serialize headless tests so that we don't try to bind the port concurrently. Its OK to run another headless test if an earlier one panicked. * JsValue: Add {is,as}_{object,function} methods Allows dynamically casting values to `js::Object` and `js::Function`. * tidy: Fix whitespace and missing semicolons * Allow for dynamic feature detection of methods If we create bindings to a method that doesn't exist in this implementation, then it shouldn't fail until if/when we actually try and invoke that missing method. * tests: Do feature detection in Array.prototype.values test * Add JsValue::{is_string, as_js_string} methods And document all the cast/convert/check methods for js value. * eslint: allow backtick string literals * Only generate a fallback import function for non-structural imports
2018-07-09 16:35:25 -07:00
pub fn is_structural(attrs: &[Box<ExtendedAttribute>]) -> bool {
attrs.iter().any(|attr| match &**attr {
ExtendedAttribute::NoArguments(webidl::ast::Other::Identifier(name)) => {
Create the `web-sys` crate mechanically from WebIDL (#409) * Create a new `web-sys` crate This will eventually contain all the WebIDL-generated bindings to Web APIs. * ci: Test the new `web-sys` crate in CI * web-sys: Add a small README * web-sys: Vendor all the WebIDL files from mozilla-central * backend: Add a pass to remove AST items that use undefined imports This is necessary for the WebIDL frontend, which can't translate many WebIDL constructs into equivalent wasm-bindgen AST things yet. It lets us make incremental progress: we can generate bindings to methods we can support right now even though there might be methods on the same interface that we can't support yet. * webidl: Add a bunch of missing semicolons * webidl: Make parsing private It was only `pub` so that we could test it, but we ended up moving towards integration tests rather than unit tests that assert particular ASTs are parsed from WebIDL files. * webidl: Remove uses of undefined import types * test-project-builder: Build projects in "very verbose" mode This helps for debugging failing WebIDL-related tests. * test-project-builder: Add more profiling timers * test-project-builder: Detect when webpack-dev-server fails Instead of going into an infinite loop, detect when webpack-dev-server fails to start up and early exit the test. * webidl: Specify version for dev-dependency on wasm-bindgen-backend Instead of only a relative path. * guide: Add section about contributing to `web-sys` * WIP enable Event.webidl Still need to fix and finish the test. * Update expected webidl output * Start out a test's status as incomplete That way if we don't fill it in the error message doesn't look quite so bizarre * Fix onerror function in headless mode Otherwise we don't see any output! * Fix package.json/node_modules handling in project generation Make sure these are looked up in the git project root rather than the crate root * Avoid logging body text This was meant for debugging and is otherwise pretty noisy * Fix a relative path * More expected test fixes * Fix a typo * test-project-builder: Allow asynchronous tests * webidl: Convert [Unforgeable] attributes into `#[wasm_bindgen(structural)]` Fixes #432 * test-project-builder: Print generated WebIDL bindings for debugging purposes Helps debug bad WebIDL bindings generation inside tests. * When we can't find a descriptor, say which one can't be found This helps when debugging things that need to become structural. * web-sys: Test bindings for Event * ci: Use `--manifest-path dir` instead of `cd dir && ...` * web-sys: Just move .webidl files isntead of symlinking to enable them * tests: Polyfill Array.prototype.values for older browsers in CI * test-project-builder: Don't panic on poisoned headless test mutex We only use it to serialize headless tests so that we don't try to bind the port concurrently. Its OK to run another headless test if an earlier one panicked. * JsValue: Add {is,as}_{object,function} methods Allows dynamically casting values to `js::Object` and `js::Function`. * tidy: Fix whitespace and missing semicolons * Allow for dynamic feature detection of methods If we create bindings to a method that doesn't exist in this implementation, then it shouldn't fail until if/when we actually try and invoke that missing method. * tests: Do feature detection in Array.prototype.values test * Add JsValue::{is_string, as_js_string} methods And document all the cast/convert/check methods for js value. * eslint: allow backtick string literals * Only generate a fallback import function for non-structural imports
2018-07-09 16:35:25 -07:00
name == "Unforgeable"
}
_ => false,
Create the `web-sys` crate mechanically from WebIDL (#409) * Create a new `web-sys` crate This will eventually contain all the WebIDL-generated bindings to Web APIs. * ci: Test the new `web-sys` crate in CI * web-sys: Add a small README * web-sys: Vendor all the WebIDL files from mozilla-central * backend: Add a pass to remove AST items that use undefined imports This is necessary for the WebIDL frontend, which can't translate many WebIDL constructs into equivalent wasm-bindgen AST things yet. It lets us make incremental progress: we can generate bindings to methods we can support right now even though there might be methods on the same interface that we can't support yet. * webidl: Add a bunch of missing semicolons * webidl: Make parsing private It was only `pub` so that we could test it, but we ended up moving towards integration tests rather than unit tests that assert particular ASTs are parsed from WebIDL files. * webidl: Remove uses of undefined import types * test-project-builder: Build projects in "very verbose" mode This helps for debugging failing WebIDL-related tests. * test-project-builder: Add more profiling timers * test-project-builder: Detect when webpack-dev-server fails Instead of going into an infinite loop, detect when webpack-dev-server fails to start up and early exit the test. * webidl: Specify version for dev-dependency on wasm-bindgen-backend Instead of only a relative path. * guide: Add section about contributing to `web-sys` * WIP enable Event.webidl Still need to fix and finish the test. * Update expected webidl output * Start out a test's status as incomplete That way if we don't fill it in the error message doesn't look quite so bizarre * Fix onerror function in headless mode Otherwise we don't see any output! * Fix package.json/node_modules handling in project generation Make sure these are looked up in the git project root rather than the crate root * Avoid logging body text This was meant for debugging and is otherwise pretty noisy * Fix a relative path * More expected test fixes * Fix a typo * test-project-builder: Allow asynchronous tests * webidl: Convert [Unforgeable] attributes into `#[wasm_bindgen(structural)]` Fixes #432 * test-project-builder: Print generated WebIDL bindings for debugging purposes Helps debug bad WebIDL bindings generation inside tests. * When we can't find a descriptor, say which one can't be found This helps when debugging things that need to become structural. * web-sys: Test bindings for Event * ci: Use `--manifest-path dir` instead of `cd dir && ...` * web-sys: Just move .webidl files isntead of symlinking to enable them * tests: Polyfill Array.prototype.values for older browsers in CI * test-project-builder: Don't panic on poisoned headless test mutex We only use it to serialize headless tests so that we don't try to bind the port concurrently. Its OK to run another headless test if an earlier one panicked. * JsValue: Add {is,as}_{object,function} methods Allows dynamically casting values to `js::Object` and `js::Function`. * tidy: Fix whitespace and missing semicolons * Allow for dynamic feature detection of methods If we create bindings to a method that doesn't exist in this implementation, then it shouldn't fail until if/when we actually try and invoke that missing method. * tests: Do feature detection in Array.prototype.values test * Add JsValue::{is_string, as_js_string} methods And document all the cast/convert/check methods for js value. * eslint: allow backtick string literals * Only generate a fallback import function for non-structural imports
2018-07-09 16:35:25 -07:00
})
}
pub fn throws(attrs: &[Box<ExtendedAttribute>]) -> bool {
attrs.iter().any(|attr| match &**attr {
ExtendedAttribute::NoArguments(webidl::ast::Other::Identifier(name)) => name == "Throws",
_ => false,
})
}
pub fn public() -> syn::Visibility {
syn::Visibility::Public(syn::VisPublic {
pub_token: Default::default(),
})
}