Skip to content

Commit

Permalink
Merge pull request #1449 from alexcrichton/no-interface-objects
Browse files Browse the repository at this point in the history
Support [NoInterfaceObject] in `web-sys`
  • Loading branch information
alexcrichton authored Apr 15, 2019
2 parents 526b253 + 01a5223 commit 3ab9bb1
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 17 deletions.
78 changes: 78 additions & 0 deletions crates/web-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ Algorithm = []
AlignSetting = []
AnalyserNode = []
AnalyserOptions = []
AngleInstancedArrays = []
Animation = []
AnimationEffect = []
AnimationEvent = []
AnimationEventInit = []
AnimationPlayState = []
AnimationPlaybackEvent = []
AnimationPlaybackEventInit = []
AnimationPropertyDetails = []
AnimationPropertyValueDetails = []
AnimationTimeline = []
AssignedNodesOptions = []
Expand Down Expand Up @@ -159,6 +161,7 @@ ChromeFilePropertyBag = []
ChromeWorker = []
Client = []
ClientQueryOptions = []
ClientRectsAndTexts = []
ClientType = []
Clients = []
ClipboardEvent = []
Expand Down Expand Up @@ -195,6 +198,7 @@ ContextAttributes2d = []
ConvertCoordinateOptions = []
ConvolverNode = []
ConvolverOptions = []
Coordinates = []
Credential = []
CredentialCreationOptions = []
CredentialRequestOptions = []
Expand Down Expand Up @@ -240,6 +244,7 @@ DecoderDoctorNotificationType = []
DedicatedWorkerGlobalScope = []
DelayNode = []
DelayOptions = []
DeviceAcceleration = []
DeviceAccelerationInit = []
DeviceLightEvent = []
DeviceLightEventInit = []
Expand All @@ -249,6 +254,7 @@ DeviceOrientationEvent = []
DeviceOrientationEventInit = []
DeviceProximityEvent = []
DeviceProximityEventInit = []
DeviceRotationRate = []
DeviceRotationRateInit = []
DhKeyDeriveParams = []
DirectionSetting = []
Expand Down Expand Up @@ -311,11 +317,22 @@ EventModifierInit = []
EventSource = []
EventSourceInit = []
EventTarget = []
Exception = []
ExtBlendMinmax = []
ExtColorBufferFloat = []
ExtColorBufferHalfFloat = []
ExtDisjointTimerQuery = []
ExtFragDepth = []
ExtSRgb = []
ExtShaderTextureLod = []
ExtTextureFilterAnisotropic = []
ExtendableEvent = []
ExtendableEventInit = []
ExtendableMessageEvent = []
ExtendableMessageEventInit = []
External = []
FakePluginMimeEntry = []
FakePluginTagInit = []
FetchEvent = []
FetchEventInit = []
FetchObserver = []
Expand Down Expand Up @@ -345,6 +362,7 @@ FontFace = []
FontFaceDescriptors = []
FontFaceLoadStatus = []
FontFaceSet = []
FontFaceSetIterator = []
FontFaceSetIteratorResult = []
FontFaceSetLoadEvent = []
FontFaceSetLoadEventInit = []
Expand All @@ -368,8 +386,10 @@ GamepadHapticActuatorType = []
GamepadMappingType = []
GamepadPose = []
GamepadServiceTest = []
Geolocation = []
GetNotificationOptions = []
GetRootNodeOptions = []
GetUserMediaRequest = []
GridDeclaration = []
GridTrackState = []
GroupedHistoryEventInit = []
Expand Down Expand Up @@ -416,6 +436,7 @@ HtmlHeadElement = []
HtmlHeadingElement = []
HtmlHrElement = []
HtmlHtmlElement = []
HtmlHyperlinkElementUtils = []
HtmlIFrameElement = []
HtmlImageElement = []
HtmlInputElement = []
Expand Down Expand Up @@ -491,10 +512,12 @@ IdbVersionChangeEventInit = []
IdleDeadline = []
IdleRequestOptions = []
IirFilterNode = []
IirFilterOptions = []
ImageBitmap = []
ImageBitmapFormat = []
ImageBitmapRenderingContext = []
ImageCapture = []
ImageCaptureError = []
ImageCaptureErrorEvent = []
ImageCaptureErrorEventInit = []
ImageData = []
Expand All @@ -505,12 +528,14 @@ IntersectionObserver = []
IntersectionObserverEntry = []
IntersectionObserverEntryInit = []
IntersectionObserverInit = []
IntlUtils = []
IterableKeyAndValueResult = []
IterableKeyOrValueResult = []
IterationCompositeOperation = []
JsonWebKey = []
KeyAlgorithm = []
KeyEvent = []
KeyIdsInitData = []
KeyboardEvent = []
KeyboardEventInit = []
KeyframeEffect = []
Expand All @@ -519,6 +544,7 @@ L10nElement = []
L10nValue = []
LifecycleCallbacks = []
LineAlignSetting = []
ListBoxObject = []
LocalMediaStream = []
LocaleInfo = []
Location = []
Expand Down Expand Up @@ -569,6 +595,7 @@ MediaStreamAudioDestinationNode = []
MediaStreamAudioSourceNode = []
MediaStreamAudioSourceOptions = []
MediaStreamConstraints = []
MediaStreamError = []
MediaStreamEvent = []
MediaStreamEventInit = []
MediaStreamTrack = []
Expand Down Expand Up @@ -602,6 +629,7 @@ MimeTypeArray = []
MouseEvent = []
MouseEventInit = []
MouseScrollEvent = []
MozDebug = []
MutationEvent = []
MutationObserver = []
MutationObserverInit = []
Expand All @@ -612,6 +640,7 @@ NativeOsFileReadOptions = []
NativeOsFileWriteAtomicOptions = []
NavigationType = []
Navigator = []
NavigatorAutomationInformation = []
NetworkCommandOptions = []
NetworkInformation = []
NetworkResultOptions = []
Expand All @@ -627,6 +656,13 @@ NotificationEventInit = []
NotificationOptions = []
NotificationPermission = []
ObserverCallback = []
OesElementIndexUint = []
OesStandardDerivatives = []
OesTextureFloat = []
OesTextureFloatLinear = []
OesTextureHalfFloat = []
OesTextureHalfFloatLinear = []
OesVertexArrayObject = []
OfflineAudioCompletionEvent = []
OfflineAudioCompletionEventInit = []
OfflineAudioContext = []
Expand Down Expand Up @@ -672,6 +708,7 @@ PerformanceNavigation = []
PerformanceNavigationTiming = []
PerformanceObserver = []
PerformanceObserverEntryList = []
PerformanceObserverInit = []
PerformanceResourceTiming = []
PerformanceServerTiming = []
PerformanceTiming = []
Expand All @@ -693,7 +730,9 @@ PopStateEvent = []
PopStateEventInit = []
PopupBlockedEvent = []
PopupBlockedEventInit = []
Position = []
PositionAlignSetting = []
PositionError = []
PositionOptions = []
Presentation = []
PresentationAvailability = []
Expand All @@ -716,9 +755,11 @@ ProfileTimelineStackFrame = []
ProfileTimelineWorkerOperationType = []
ProgressEvent = []
ProgressEventInit = []
PromiseNativeHandler = []
PromiseRejectionEvent = []
PromiseRejectionEventInit = []
PublicKeyCredential = []
PublicKeyCredentialCreationOptions = []
PublicKeyCredentialDescriptor = []
PublicKeyCredentialEntity = []
PublicKeyCredentialParameters = []
Expand Down Expand Up @@ -792,6 +833,7 @@ RtcIdentityAssertionResult = []
RtcIdentityProvider = []
RtcIdentityProviderDetails = []
RtcIdentityProviderOptions = []
RtcIdentityProviderRegistrar = []
RtcIdentityValidationResult = []
RtcInboundRtpStreamStats = []
RtcLifecycleEvent = []
Expand Down Expand Up @@ -844,6 +886,7 @@ ScreenOrientation = []
ScriptProcessorNode = []
ScrollAreaEvent = []
ScrollBehavior = []
ScrollBoxObject = []
ScrollIntoViewOptions = []
ScrollLogicalPosition = []
ScrollOptions = []
Expand Down Expand Up @@ -952,7 +995,27 @@ SvgMetadataElement = []
SvgNumber = []
SvgNumberList = []
SvgPathElement = []
SvgPathSeg = []
SvgPathSegArcAbs = []
SvgPathSegArcRel = []
SvgPathSegClosePath = []
SvgPathSegCurvetoCubicAbs = []
SvgPathSegCurvetoCubicRel = []
SvgPathSegCurvetoCubicSmoothAbs = []
SvgPathSegCurvetoCubicSmoothRel = []
SvgPathSegCurvetoQuadraticAbs = []
SvgPathSegCurvetoQuadraticRel = []
SvgPathSegCurvetoQuadraticSmoothAbs = []
SvgPathSegCurvetoQuadraticSmoothRel = []
SvgPathSegLinetoAbs = []
SvgPathSegLinetoHorizontalAbs = []
SvgPathSegLinetoHorizontalRel = []
SvgPathSegLinetoRel = []
SvgPathSegLinetoVerticalAbs = []
SvgPathSegLinetoVerticalRel = []
SvgPathSegList = []
SvgPathSegMovetoAbs = []
SvgPathSegMovetoRel = []
SvgPatternElement = []
SvgPoint = []
SvgPointList = []
Expand Down Expand Up @@ -1044,7 +1107,9 @@ TrackEventInit = []
TransitionEvent = []
TransitionEventInit = []
Transport = []
TreeBoxObject = []
TreeCellInfo = []
TreeView = []
TreeWalker = []
U2f = []
U2fClientData = []
Expand Down Expand Up @@ -1183,6 +1248,19 @@ WebKitCssMatrix = []
WebSocket = []
WebSocketDict = []
WebSocketElement = []
WebglColorBufferFloat = []
WebglCompressedTextureAstc = []
WebglCompressedTextureAtc = []
WebglCompressedTextureEtc = []
WebglCompressedTextureEtc1 = []
WebglCompressedTexturePvrtc = []
WebglCompressedTextureS3tc = []
WebglCompressedTextureS3tcSrgb = []
WebglDebugRendererInfo = []
WebglDebugShaders = []
WebglDepthTexture = []
WebglDrawBuffers = []
WebglLoseContext = []
WebrtcGlobalStatisticsReport = []
WheelEvent = []
WheelEventInit = []
Expand Down
1 change: 1 addition & 0 deletions crates/webidl-tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ pub mod global;
pub mod namespace;
pub mod simple;
pub mod throws;
pub mod no_interface;
8 changes: 8 additions & 0 deletions crates/webidl-tests/no_interface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
global.GetNoInterfaceObject = class {
static get() {
return {
number: 3,
foo: () => {},
}
}
};
11 changes: 11 additions & 0 deletions crates/webidl-tests/no_interface.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use js_sys::Object;
use wasm_bindgen_test::*;

include!(concat!(env!("OUT_DIR"), "/no_interface.rs"));

#[wasm_bindgen_test]
fn smoke() {
let obj = GetNoInterfaceObject::get();
assert_eq!(obj.number(), 3.0);
obj.foo();
}
9 changes: 9 additions & 0 deletions crates/webidl-tests/no_interface.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[NoInterfaceObject]
interface NoInterfaceObject {
readonly attribute double number;
void foo();
};

interface GetNoInterfaceObject {
static NoInterfaceObject get();
};
25 changes: 9 additions & 16 deletions crates/webidl/src/first_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub(crate) struct FirstPassRecord<'src> {
pub(crate) struct InterfaceData<'src> {
/// Whether only partial interfaces were encountered
pub(crate) partial: bool,
pub(crate) has_interface: bool,
pub(crate) deprecated: Option<String>,
pub(crate) attributes: Vec<&'src AttributeInterfaceMember<'src>>,
pub(crate) consts: Vec<&'src ConstMember<'src>>,
Expand Down Expand Up @@ -303,22 +304,14 @@ impl<'src> FirstPass<'src, ()> for weedle::InterfaceDefinition<'src> {
return Ok(());
}

if util::is_no_interface_object(&self.attributes) {
log::info!(
"Skipping because of `NoInterfaceObject` attribute: {:?}",
self.identifier.0
);
return Ok(());
}

{
let interface_data = record.interfaces.entry(self.identifier.0).or_default();
interface_data.partial = false;
interface_data.superclass = self.inheritance.map(|s| s.identifier.0);
interface_data.definition_attributes = self.attributes.as_ref();
interface_data.deprecated =
util::get_rust_deprecated(&self.attributes).map(|s| s.to_string());
}
let interface_data = record.interfaces.entry(self.identifier.0).or_default();
interface_data.partial = false;
interface_data.superclass = self.inheritance.map(|s| s.identifier.0);
interface_data.definition_attributes = self.attributes.as_ref();
interface_data.deprecated =
util::get_rust_deprecated(&self.attributes).map(|s| s.to_string());
interface_data.has_interface =
!util::is_no_interface_object(&self.attributes);
if let Some(attrs) = &self.attributes {
for attr in attrs.body.list.iter() {
process_interface_attribute(record, self.identifier.0, attr);
Expand Down
6 changes: 5 additions & 1 deletion crates/webidl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,11 @@ impl<'src> FirstPassRecord<'src> {
attrs,
doc_comment: None,
instanceof_shim: format!("__widl_instanceof_{}", name),
is_type_of: None,
is_type_of: if data.has_interface {
None
} else {
Some(syn::parse_quote!{ |_| false })
},
extends: Vec::new(),
vendor_prefixes: Vec::new(),
};
Expand Down

0 comments on commit 3ab9bb1

Please sign in to comment.