Closed Bug 1230864 Opened 9 years ago Closed 9 years ago

Extending Event interface in a JS-based WebIDL binding

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: marcosc, Unassigned)

Details

Attachments

(1 file)

Attached file MozNewTab.webidl
I'm trying to implement the following: ``` [JSImplementation="@mozilla.org/MozEngineChangeEvent;1", Constructor(DOMString type, optional EngineChangeEventInit eventInitDict)] interface MozEngineChangeEvent : Event { readonly attribute MozSearchEngineDetails engine; }; dictionary EngineChangeEventInit : EventInit { MozSearchEngineDetails engine; }; ``` (note, I've excluded MozSearchEngineDetails as it works just fine... but you can see the whole API in the attached IDL file) When I mach build, I get the following error: 0:10.66 In file included from /Users/marcos/newtab-dev/obj-x86_64-apple-darwin15.0.0/dom/bindings/RegisterBindings.cpp:320: 0:10.66 ../../dist/include/mozilla/dom/MozNewTabBinding.h:915:21: error: declaration of 'WrapObject' overrides a 'final' function 0:10.66 virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; 0:10.66 ^ 0:10.66 ../../dist/include/mozilla/dom/Event.h:93:21: note: overridden virtual function is here 0:10.66 virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final; 0:10.66 ^ 0:10.66 In file included from /Users/marcos/newtab-dev/obj-x86_64-apple-darwin15.0.0/dom/bindings/RegisterBindings.cpp:320: 0:10.66 Warning: -Woverloaded-virtual in /Users/marcos/newtab-dev/obj-x86_64-apple-darwin15.0.0/dist/include/mozilla/dom/MozNewTabBinding.h: 'mozilla::dom::MozEngineChangeEvent::GetIsTrusted' hides overloaded virtual function 0:10.66 ../../dist/include/mozilla/dom/MozNewTabBinding.h:922:8: warning: 'mozilla::dom::MozEngineChangeEvent::GetIsTrusted' hides overloaded virtual function [-Woverloaded-virtual] 0:10.66 bool GetIsTrusted(ErrorResult& aRv, JSCompartment* aCompartment = nullptr) const; 0:10.67 ^ 0:10.67 ../../dist/include/mozilla/dom/Event.h:113:3: note: hidden overloaded virtual function 'mozilla::dom::Event::GetIsTrusted' declared here: different number of parameters (1 vs 2) 0:10.67 NS_DECL_NSIDOMEVENT 0:10.67 ^ 0:10.67 ../../dist/include/nsIDOMEvent.h:160:14: note: expanded from macro 'NS_DECL_NSIDOMEVENT' 0:10.67 NS_IMETHOD GetIsTrusted(bool *aIsTrusted) override; \ 0:10.67 ^ 0:11.26 In file included from /Users/marcos/newtab-dev/obj-x86_64-apple-darwin15.0.0/dom/bindings/UnifiedBindings12.cpp:278: 0:11.26 In file included from ./MozNewTabBinding.cpp:7: 0:11.26 ../../dist/include/mozilla/dom/MozNewTabBinding.h:915:21: error: declaration of 'WrapObject' overrides a 'final' function 0:11.26 virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; 0:11.26 ^ 0:11.26 ../../dist/include/mozilla/dom/Event.h:93:21: note: overridden virtual function is here 0:11.26 virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final; 0:11.26 ^ 0:11.26 In file included from /Users/marcos/newtab-dev/obj-x86_64-apple-darwin15.0.0/dom/bindings/UnifiedBindings12.cpp:278: 0:11.26 In file included from ./MozNewTabBinding.cpp:7: 0:11.26 Warning: -Woverloaded-virtual in /Users/marcos/newtab-dev/obj-x86_64-apple-darwin15.0.0/dist/include/mozilla/dom/MozNewTabBinding.h: 'mozilla::dom::MozEngineChangeEvent::GetIsTrusted' hides overloaded virtual function 0:11.26 ../../dist/include/mozilla/dom/MozNewTabBinding.h:922:8: warning: 'mozilla::dom::MozEngineChangeEvent::GetIsTrusted' hides overloaded virtual function [-Woverloaded-virtual] 0:11.26 bool GetIsTrusted(ErrorResult& aRv, JSCompartment* aCompartment = nullptr) const; 0:11.26 ^ 0:11.26 ../../dist/include/mozilla/dom/Event.h:113:3: note: hidden overloaded virtual function 'mozilla::dom::Event::GetIsTrusted' declared here: different number of parameters (1 vs 2) 0:11.26 NS_DECL_NSIDOMEVENT 0:11.26 ^ 0:11.26 ../../dist/include/nsIDOMEvent.h:160:14: note: expanded from macro 'NS_DECL_NSIDOMEVENT' 0:11.26 NS_IMETHOD GetIsTrusted(bool *aIsTrusted) override; \ 0:11.26 ^ 0:11.41 In file included from /Users/marcos/newtab-dev/obj-x86_64-apple-darwin15.0.0/dom/bindings/UnifiedBindings12.cpp:278: 0:11.41 ./MozNewTabBinding.cpp:8600:19: error: no matching constructor for initialization of 'mozilla::dom::Event' 0:11.41 : mozilla::dom::Event(aParent), 0:11.41 ^ ~~~~~~~ 0:11.41 ../../dist/include/mozilla/dom/Event.h:49:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'nsIGlobalObject *' to 'const mozilla::dom::Event' for 1st argument 0:11.41 class Event : public EventBase, 0:11.41 ^ 0:11.41 ../../dist/include/mozilla/dom/Event.h:56:12: note: candidate constructor not viable: no known conversion from 'nsIGlobalObject *' to 'nsPIDOMWindow *' for 1st argument 0:11.41 explicit Event(nsPIDOMWindow* aWindow); 0:11.41 ^ 0:11.41 ../../dist/include/mozilla/dom/Event.h:53:3: note: candidate constructor not viable: requires 3 arguments, but 1 was provided 0:11.41 Event(EventTarget* aOwner, 0:11.41 ^ 0:11.52 1 warning and 1 error generated. 0:11.54 0:11.54 In the directory /Users/marcos/newtab-dev/obj-x86_64-apple-darwin15.0.0/dom/bindings 0:11.54 The following command failed to execute properly: 0:11.54 /usr/bin/clang++ -o RegisterBindings.o -c -fvisibility=hidden -fvisibility-inlines-hidden -DOS_POSIX=1 -DOS_MACOSX=1 -DHAVE_SIDEBAR -DSTATIC_EXPORTABLE_JS_API -DMOZILLA_INTERNAL_API -DIMPL_LIBXUL -I/Users/marcos/newtab-dev/dom/bindings -I. -I../../dist/include/mozilla/dom -I/Users/marcos/newtab-dev/dom/base -I/Users/marcos/newtab-dev/dom/battery -I/Users/marcos/newtab-dev/dom/bluetooth/common/webapi -I/Users/marcos/newtab-dev/dom/camera -I/Users/marcos/newtab-dev/dom/canvas -I/Users/marcos/newtab-dev/dom/geolocation -I/Users/marcos/newtab-dev/dom/html -I/Users/marcos/newtab-dev/dom/indexedDB -I/Users/marcos/newtab-dev/dom/media/webaudio -I/Users/marcos/newtab-dev/dom/media/webspeech/recognition -I/Users/marcos/newtab-dev/dom/svg -I/Users/marcos/newtab-dev/dom/workers -I/Users/marcos/newtab-dev/dom/xbl -I/Users/marcos/newtab-dev/dom/xml -I/Users/marcos/newtab-dev/dom/xslt/base -I/Users/marcos/newtab-dev/dom/xslt/xpath -I/Users/marcos/newtab-dev/dom/xul -I/Users/marcos/newtab-dev/js/xpconnect/src -I/Users/marcos/newtab-dev/js/xpconnect/wrappers -I/Users/marcos/newtab-dev/layout/style -I/Users/marcos/newtab-dev/layout/xul/tree -I/Users/marcos/newtab-dev/media/mtransport -I/Users/marcos/newtab-dev/media/webrtc -I/Users/marcos/newtab-dev/media/webrtc/signaling/src/common/time_profiling -I/Users/marcos/newtab-dev/media/webrtc/signaling/src/peerconnection -I../../ipc/ipdl/_ipdlheaders -I/Users/marcos/newtab-dev/ipc/chromium/src -I/Users/marcos/newtab-dev/ipc/glue -I../../dist/include -I/Users/marcos/newtab-dev/obj-x86_64-apple-darwin15.0.0/dist/include/nspr -I/Users/marcos/newtab-dev/obj-x86_64-apple-darwin15.0.0/dist/include/nss -fPIC -DMOZILLA_CLIENT -include ../../mozilla-config.h -MD -MP -MF .deps/RegisterBindings.o.pp -Qunused-arguments -Qunused-arguments -Wno-unused-local-typedef -Wall -Wempty-body -Woverloaded-virtual -Wsign-compare -Wwrite-strings -Wno-invalid-offsetof -Wno-inline-new-delete -Wno-unused-local-typedef -Wno-c++0x-extensions -Wno-extended-offsetof -Wno-unknown-warning-option -Wno-return-type-c-linkage -fno-exceptions -fno-strict-aliasing -fno-rtti -fno-exceptions -fno-math-errno -std=gnu++0x -pthread -DNO_X11 -pipe -Wno-uninitialized -DDEBUG -DTRACING -g -O3 -fno-omit-frame-pointer /Users/marcos/newtab-dev/obj-x86_64-apple-darwin15.0.0/dom/bindings/RegisterBindings.cpp 0:11.54 make[5]: *** [RegisterBindings.o] Error 1 0:11.54 make[5]: *** Waiting for unfinished jobs.... 0:11.97 1 warning and 2 errors generated. 0:11.99 0:11.99 In the directory /Users/marcos/newtab-dev/obj-x86_64-apple-darwin15.0.0/dom/bindings 0:11.99 The following command failed to execute properly: 0:11.99 /usr/bin/clang++ -o UnifiedBindings12.o -c -fvisibility=hidden -fvisibility-inlines-hidden -DOS_POSIX=1 -DOS_MACOSX=1 -DHAVE_SIDEBAR -DSTATIC_EXPORTABLE_JS_API -DMOZILLA_INTERNAL_API -DIMPL_LIBXUL -I/Users/marcos/newtab-dev/dom/bindings -I. -I../../dist/include/mozilla/dom -I/Users/marcos/newtab-dev/dom/base -I/Users/marcos/newtab-dev/dom/battery -I/Users/marcos/newtab-dev/dom/bluetooth/common/webapi -I/Users/marcos/newtab-dev/dom/camera -I/Users/marcos/newtab-dev/dom/canvas -I/Users/marcos/newtab-dev/dom/geolocation -I/Users/marcos/newtab-dev/dom/html -I/Users/marcos/newtab-dev/dom/indexedDB -I/Users/marcos/newtab-dev/dom/media/webaudio -I/Users/marcos/newtab-dev/dom/media/webspeech/recognition -I/Users/marcos/newtab-dev/dom/svg -I/Users/marcos/newtab-dev/dom/workers -I/Users/marcos/newtab-dev/dom/xbl -I/Users/marcos/newtab-dev/dom/xml -I/Users/marcos/newtab-dev/dom/xslt/base -I/Users/marcos/newtab-dev/dom/xslt/xpath -I/Users/marcos/newtab-dev/dom/xul -I/Users/marcos/newtab-dev/js/xpconnect/src -I/Users/marcos/newtab-dev/js/xpconnect/wrappers -I/Users/marcos/newtab-dev/layout/style -I/Users/marcos/newtab-dev/layout/xul/tree -I/Users/marcos/newtab-dev/media/mtransport -I/Users/marcos/newtab-dev/media/webrtc -I/Users/marcos/newtab-dev/media/webrtc/signaling/src/common/time_profiling -I/Users/marcos/newtab-dev/media/webrtc/signaling/src/peerconnection -I../../ipc/ipdl/_ipdlheaders -I/Users/marcos/newtab-dev/ipc/chromium/src -I/Users/marcos/newtab-dev/ipc/glue -I../../dist/include -I/Users/marcos/newtab-dev/obj-x86_64-apple-darwin15.0.0/dist/include/nspr -I/Users/marcos/newtab-dev/obj-x86_64-apple-darwin15.0.0/dist/include/nss -fPIC -DMOZILLA_CLIENT -include ../../mozilla-config.h -MD -MP -MF .deps/UnifiedBindings12.o.pp -Qunused-arguments -Qunused-arguments -Wno-unused-local-typedef -Wall -Wempty-body -Woverloaded-virtual -Wsign-compare -Wwrite-strings -Wno-invalid-offsetof -Wno-inline-new-delete -Wno-unused-local-typedef -Wno-c++0x-extensions -Wno-extended-offsetof -Wno-unknown-warning-option -Wno-return-type-c-linkage -fno-exceptions -fno-strict-aliasing -fno-rtti -fno-exceptions -fno-math-errno -std=gnu++0x -pthread -DNO_X11 -pipe -Wno-uninitialized -DDEBUG -DTRACING -g -O3 -fno-omit-frame-pointer /Users/marcos/newtab-dev/obj-x86_64-apple-darwin15.0.0/dom/bindings/UnifiedBindings12.cpp 0:11.99 make[5]: *** [UnifiedBindings12.o] Error 1 0:12.05 Unified_cpp_perfmonitoring0.o 0:12.05 UnifiedProtocols0.o 0:12.05 UnifiedProtocols1.o 0:14.36 libtoolkit_components_perfmonitoring.a.desc
Flags: needinfo?(bzbarsky)
Summary: Extending Event in a WebIDL binding → Extending Event interface in a JS-based WebIDL binding
(In reply to Marcos Caceres [:marcosc] from comment #0) > Created attachment 8696392 [details] > MozNewTab.webidl > > I'm trying to implement the following: > > ``` > [JSImplementation="@mozilla.org/MozEngineChangeEvent;1", > Constructor(DOMString type, optional EngineChangeEventInit eventInitDict)] > interface MozEngineChangeEvent : Event { > readonly attribute MozSearchEngineDetails engine; > }; > > dictionary EngineChangeEventInit : EventInit { > MozSearchEngineDetails engine; > }; First, 'engine' in the dictionary must be either required or nullable ('?'), and if nullable, make the attribute in the interface also nullable. And then you can implement the event using event codegen. Just have the interface and dictionary in the .webidl and add the .webidl file to the GENERATED_EVENTS_WEBIDL_FILES list in http://mxr.mozilla.org/mozilla-central/source/dom/webidl/moz.build and compile. Generated .h will be <objdir>/dist/include/mozilla/dom/*Event.h and .cpp <objdir>/<dom/bindings/*Event.cpp (I'm hoping implementing events in js doesn't even work, but not sure.)
Flags: needinfo?(bzbarsky)
Yeah, there's all sorts of stuff Event does that makes the normal JS-impl codegen not play with it. But I agree with Olli: you probably don't need to do JS-implemented events at all. If you think you do, I'd love to understand why before putting in the work to make it work.
OMG, it worked! I don't tell you guys I love you often enough :) Thank you!
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → WORKSFORME
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: