Closed Bug 1428438 Opened 7 years ago Closed 6 years ago

Cannot use WebGLBuffer as key to WeakMap

Categories

(Core :: DOM: Bindings (WebIDL), defect)

defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 1351501

People

(Reporter: jgmize, Unassigned)

Details

I first came across this in https://github.com/oussama/webgl-rs/issues/1 with steps to replicate copied from my commment there: var canvas = document.createElement('canvas') var ctx = canvas.getContext('webgl') var buffer = ctx.createBuffer() var weakMap = new WeakMap() weakMap.set(buffer, 'some value') Results in the following error on Firefox Nightly: TypeError: cannot use the given object as a weak map key The same code works in current chrom{e,ium} for me.
Issue still present in firefox 58.0.2 : http://og.tn/webgl-rs/example/bin/simple/ Yet, buffer is an object, so it should be valid as a weakmap key : >> var canvas = document.createElement('canvas') var ctx = canvas.getContext('webgl') var buffer = ctx.createBuffer() undefined >> buffer WebGLBuffer { } >> typeof buffer "object"
WebGLBuffer is a normal WebIDL object, implements nsWrapperCache, so I would have expected the JS engine to accept it.
Component: Canvas: WebGL → JavaScript Engine
The error mentioned in comment #0 is thrown from here [1], so it indicates that the "Preserve Wrapper Callback" cannot handle WebGLBuffer objects. The relevant "Preserve Wrapper Callback" is defined here [2], so it actually looks like a DOM issue? [1] https://searchfox.org/mozilla-central/rev/55da592d85c2baf8d8818010c41d9738c97013d2/js/src/builtin/WeakMapObject-inl.h#27-30 [2] https://searchfox.org/mozilla-central/rev/55da592d85c2baf8d8818010c41d9738c97013d2/dom/bindings/BindingUtils.cpp#1149-1168
Jon, do you think it makes sense to move this bug (and other similar bugs like bug 1489145, bug 1449485, and bug 1351501) to the DOM component, because it seems this is something which needs to be handled in DOM code?
Flags: needinfo?(jcoppeard)
Yes, I think that makes sense. Passing on the NI to Andrew who wrote TryPreserveWrapper().
Component: JavaScript Engine → DOM: Bindings (WebIDL)
Flags: needinfo?(jcoppeard) → needinfo?(continuation)
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → DUPLICATE
Flags: needinfo?(continuation)
Thanks for finding all of these dupes, anba.
You need to log in before you can comment on or make changes to this bug.