-
-
Notifications
You must be signed in to change notification settings - Fork 477
Wrapping Event in a C++ class so that every where you pass an event it works. #1661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
wrt, I'm trying to verify if this is possible or not. My impression is it's not possible and that I have to do something like create |
Just to make it clear what my goal is here. I'm trying to get dawn.node to be spec compliant. Dawn is Chromium's implementation of the WebGPU Spec and dawn.node is trying to bring the same API to node.js That spec has a few requirements of extending existing classes For example
This means, for example, if you patch EventTarget.prototype.dispatchEvent = (function(origFn) {
return function(event) {
console.log('type:', event.type);
return origFn.call(this, event);
};
})(EventTarget.prototype.dispatchEvent);
someGPUDevice.dispatchEvent(new Event('foobar')); // should see type: foobar in console Similarly, as mentioned above, a custom event WebGPU event, implemented by dawn.node, needs to act like an
This means for example, it's valid to dispatchEvent an const target = new EventTarget();
target.dispatchEvent(new GPUUncapturedErrorEvent('uncapturederror', {
error: new GPUValidationError('msg'),
}); Which is the issue above. Several other requirements GPUDevice.prototype instanceof EventTarget // should be true
someGPUDevice instanceof EventTarget // should be true
someGPUDevice instanceof GPUDevice // should be true I feel like I'm reading around the net and in issues in this repo that NAPI doesn't support what I'm trying to do and basically I'm trying to verify that. |
Node-API does not currently provide a mechanism to create a C++ class that extends a JavaScript class. There's some technical limitations (as a class in V8 is a FunctionTemplate, which does not have a corresponding Node-API counterpart). Have you tried prototype manipulation, eg. with Perhaps look at #229 for some other discussions regarding same. Let us know how it turns out! |
The Node NAPI provides no way to do this nodejs/node-addon-api#1661 To be spec compliant GPUUncapturedErrorEvent is required to inherit from Event so it can be used everywhere an Event can be used. The workaround is to manually implement GPUUncapturedErrorEvent as a JavaScript class. Note: This class is not used in dawn.node yet but this CL makes the CTS test webgpu:idl,javascript:inheritance:type="GPUUncapturedErrorEvent" pass. A future CL will use this class. Bug: 419128706 Depends-On: Ib56a6403bef7f677e9f5f740193770012de30ad4 Change-Id: Ia388562d8d7f02458e36b29db1a5acb8fcac03e2 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/243294 Reviewed-by: Corentin Wallez <[email protected]> Commit-Queue: Gregg Tavares <[email protected]>
in JavaScript I can do this
Is it possible to have
MyEvent
be a C++ class?In my current attempt, when I call
target.dispatchEvent
I getI tried setting the prototype chain in C++ and this passes
but of course it's not actually an
Event
, it's a non-event who's prototype chain containsEvent
which is what node is complaining about.The text was updated successfully, but these errors were encountered: