dawn.node: Do not expose non-WebGPU interfaces at global scope.

This remove some interfaces like OffscreenCanvas from the global scope
because dawn.node is not capable to usefully create them. The CTS
uses the absence of these interfaces to skip tests when needed.

Bug: dawn:1123
Change-Id: I6d57600ba6b41be58c541d1f8091e7e88781f04f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/85364
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2022-04-01 13:11:58 +00:00 committed by Dawn LUCI CQ
parent 63fe6e11cd
commit 60e5ab281c
3 changed files with 24 additions and 13 deletions

View File

@ -14,6 +14,10 @@
// An IDL file that provides stub definitions for dictionaries and interfaces // An IDL file that provides stub definitions for dictionaries and interfaces
// used by the webgpu.idl file // used by the webgpu.idl file
//
// The [LegacyNoInterfaceObject] annotation asks idlgen to not create a global constructor for
// an interface. It is a real WebIDL annotation but we use it liberally here.
// https://webidl.spec.whatwg.org/#LegacyNoInterfaceObject
dictionary EventInit { dictionary EventInit {
boolean bubbles = false; boolean bubbles = false;
@ -21,25 +25,25 @@ dictionary EventInit {
boolean composed = false; boolean composed = false;
}; };
interface Navigator { [LegacyNoInterfaceObject] interface Navigator {
readonly attribute DOMString vendorSub; readonly attribute DOMString vendorSub;
readonly attribute DOMString productSub; readonly attribute DOMString productSub;
readonly attribute DOMString vendor; readonly attribute DOMString vendor;
}; };
interface Event { [LegacyNoInterfaceObject] interface Event {
readonly attribute boolean bubbles; readonly attribute boolean bubbles;
readonly attribute boolean cancelable; readonly attribute boolean cancelable;
attribute boolean returnValue; attribute boolean returnValue;
}; };
interface WorkerNavigator{}; [LegacyNoInterfaceObject] interface WorkerNavigator{};
interface EventListener { [LegacyNoInterfaceObject] interface EventListener {
undefined handleEvent(Event event); undefined handleEvent(Event event);
}; };
interface EventTarget { [LegacyNoInterfaceObject] interface EventTarget {
undefined addEventListener(DOMString type, EventListener? callback, optional (AddEventListenerOptions or boolean) options); undefined addEventListener(DOMString type, EventListener? callback, optional (AddEventListenerOptions or boolean) options);
undefined removeEventListener(DOMString type, EventListener? callback, optional (EventListenerOptions or boolean) options); undefined removeEventListener(DOMString type, EventListener? callback, optional (EventListenerOptions or boolean) options);
boolean dispatchEvent(Event event); boolean dispatchEvent(Event event);
@ -52,7 +56,7 @@ dictionary AddEventListenerOptions : EventListenerOptions {
boolean once = false; boolean once = false;
}; };
interface HTMLVideoElement { [LegacyNoInterfaceObject] interface HTMLVideoElement {
attribute unsigned long width; attribute unsigned long width;
attribute unsigned long height; attribute unsigned long height;
readonly attribute unsigned long videoWidth; readonly attribute unsigned long videoWidth;
@ -66,19 +70,19 @@ typedef(Int8Array or Int16Array or Int32Array or Uint8Array or Uint16Array or
typedef(ArrayBufferView or ArrayBuffer) BufferSource; typedef(ArrayBufferView or ArrayBuffer) BufferSource;
interface ImageBitmap { [LegacyNoInterfaceObject] interface ImageBitmap {
readonly attribute unsigned long width; readonly attribute unsigned long width;
readonly attribute unsigned long height; readonly attribute unsigned long height;
}; };
interface HTMLCanvasElement { [LegacyNoInterfaceObject] interface HTMLCanvasElement {
attribute unsigned long width; attribute unsigned long width;
attribute unsigned long height; attribute unsigned long height;
}; };
interface OffscreenCanvas { [LegacyNoInterfaceObject] interface OffscreenCanvas {
attribute unsigned long width; attribute unsigned long width;
attribute unsigned long height; attribute unsigned long height;
}; };
interface EventHandler{}; [LegacyNoInterfaceObject] interface EventHandler{};

View File

@ -56,9 +56,11 @@ namespace {
void Initialize(Napi::Env env) { void Initialize(Napi::Env env) {
auto* wrapper = Wrappers::Init(env); auto* wrapper = Wrappers::Init(env);
auto global = env.Global(); auto global = env.Global();
{{ range $ := .Declarations}} {{- range $ := .Declarations}}
{{- if IsInterfaceOrNamespace $}} {{- if IsInterfaceOrNamespace $}}
{{- if not (HasAnnotation $ "LegacyNoInterfaceObject")}}
global.Set(Napi::String::New(env, "{{$.Name}}"), wrapper->{{$.Name}}_ctor.Value()); global.Set(Napi::String::New(env, "{{$.Name}}"), wrapper->{{$.Name}}_ctor.Value());
{{- end}}
{{- end}} {{- end}}
{{- end}} {{- end}}
} }

View File

@ -518,8 +518,13 @@ func findAnnotation(list []*ast.Annotation, name string) *ast.Annotation {
} }
func hasAnnotation(obj interface{}, name string) bool { func hasAnnotation(obj interface{}, name string) bool {
if member, ok := obj.(*ast.Member); ok { switch obj := obj.(type) {
return findAnnotation(member.Annotations, name) != nil case *ast.Member:
return findAnnotation(obj.Annotations, name) != nil
case *ast.Interface:
return findAnnotation(obj.Annotations, name) != nil
case *ast.Namespace:
return findAnnotation(obj.Annotations, name) != nil
} }
panic("Unhandled AST node type in hasAnnotation") panic("Unhandled AST node type in hasAnnotation")
} }