On Mon Jul 24 15:35:16 2023 +0000, Gabriel Ivăncescu wrote:
In that case you need **two** objects: the constructor and the instance created from it. The constructor would be as I described above, and then in `mutation_observer_ctor_value` you'd create the instance when flags are DISPATCH_CONSTRUCT (but I'd also add tests without the "new" keyword, it probably works, so you can use same path with DISPATCH_METHOD flags). window.MutationObserver is a constructor. If you write in jscript code:
var x = window.MutationObserver;
this invokes the getter and places the **constructor** into x. If you write:
var y = new window.MutationObserver();
this first invokes the getter and retrieves the (cached) constructor. Then it calls the constructor's DISPID_VALUE (`mutation_observer_ctor_value` callback from the vtbl) with DISPATCH_CONSTRUCT, which creates the instance of the mutation observer and places it into y. If you omit the `new` keyword, it uses DISPATCH_METHOD instead, which probably works as well (but really, you need to add tests for this). So a switch(...) statement here with DISPATCH_METHOD falling through DISPATCH_CONSTRUCT is probably ideal. Additionally, if you're going to add a stub instance implementation, I suggest you add some basic tests for the instance, such as what props it exposes (look on MDN and test them on mshtml, it might not expose all of them), and then you add these props to `IWineMSHTMLMutationObserver`, but of course you'll stub them out. You can then add some basic tests for the instance (in IE11, so either in es5.js, or in documentmode.js but return early if not available), and what props it exposes, maybe something like:
sync_test("MutationObserver", function() { var m; m = MutationObserver(); ok(m !== new MutationObserver(), "MutationObserver() == new MutationObserver()"); ok(new MutationObserver() !== new MutationObserver(), "new MutationObserver() == new MutationObserver()"); });
(this is very basic but you get the idea, this test will be expanded when more gets implemented) I don't know if this test will succeed, though. Note that first I create one without `new` keyword. That's why you need to test it first.
~~isn't `matchMedia` the same? why doesn't it need a separate constructor object, and make `matchMedia` a `propget`?~~