Use webidl2.js with JSON or pickle
redcrabs opened this issue · 3 comments
Hi
I'm using webidl2.js to load Web-GPU IDL specifications .
I use the parse method to parse the webidl file :
const data = fs.readFileSync('c:/gpu/web-gpu.webidl', 'utf8');
const tree = parse(data);
I want to have better control over objects, interfaces, methods, etc . For this I used stringify
to read the data as JSON but seems it's not the best way to get control over objects in WebIDL .
I'm looking to see if I should use pickle (Probably) or other techniques to have better control over objects.
Attached is the JSON output I have mentioned . (As an example I would like to access createBuffer operation with it's arguments and interface, but seems it's a bit complicated, is there a way to use webidl2js to handle this in more easier ways?
One more question is, what is the difference between webidl2js and web_idl in chromium project located here : https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/bindings/scripts/web_idl/
Any help is appreciated .
Attached is the JSON output I have mentioned . (As an example I would like to access createBuffer operation with it's arguments and interface, but seems it's a bit complicated, is there a way to use webidl2js to handle this in more easier ways?
Could you provide an example of the easier ways in your mind?
The current way would be:
const ast = parse(idl);
const interfaceGPUDevice = ast.filter(item => item.name === "GPUDevice");
const methodCreateBuffer = interfaceGPUDevice.members.filter(item => item.name === "createBuffer");
One more question is, what is the difference between webidl2js and web_idl in chromium project located here : https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/bindings/scripts/web_idl/
That tool is Blink-only with Blink-specific IDL extensions. This library does not support any nonstandard syntax.
Attached is the JSON output I have mentioned . (As an example I would like to access createBuffer operation with it's arguments and interface, but seems it's a bit complicated, is there a way to use webidl2js to handle this in more easier ways?
Could you provide an example of the easier ways in your mind?
The current way would be:
const ast = parse(idl); const interfaceGPUDevice = ast.filter(item => item.name === "GPUDevice"); const methodCreateBuffer = interfaceGPUDevice.members.filter(item => item.name === "createBuffer");One more question is, what is the difference between webidl2js and web_idl in chromium project located here : https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/bindings/scripts/web_idl/
That tool is Blink-only with Blink-specific IDL extensions. This library does not support any nonstandard syntax.
Hey! thank for your reply and for the example code .
I think there's no problem with interfaceGPUDevice but for the last line I have the following error :
C:\webgpu-test\webidl-parse\index1.js:17
const methodCreateBuffer = interfaceGPUDevice.members.filter(item => item.name === "createBuffer");
^
TypeError: Cannot read properties of undefined (reading 'filter')
at Object.<anonymous> (C:\webgpu-test\webidl-parse\index1.js:17:55)
Ah yes. Try this:
const ast = parse(idl);
const interfaceGPUDevice = ast.find(item => item.name === "GPUDevice");
const methodCreateBuffer = interfaceGPUDevice.members.find(item => item.name === "createBuffer");