skoppe / spasm

Write single page applications in D that compile to webassembly
MIT License
218 stars 17 forks source link

Node.appendChild duplicates a RAII handle #55

Closed dukc closed 3 years ago

dukc commented 3 years ago

Node.appendChild currently needs to be used this way:

auto reduntantRef = result.appendChild(*logo);
*reduntantRef.ptr = 0;

That's because appendChild copies the JsHandle contained in *logo into it's return value. If I don't manually nullify it, its destructor runs, and prematurely deletes the JavaScript object *logo refers to.

Clearly the API of Node.appendChild needs rethinking.

dukc commented 3 years ago

Oh sorry, there's the JavaScript export Node_appendChild that is called, that does copy the handle so double free should not happen. I think I was looking at appendChild JavaScript export without realizing it isn't the one that's called.

It is something else that nullified my object pointer.