Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upread_blob returns a reflector to an unrooted DOM object #21164
Comments
|
Is the rooting handled at the point of use? For example the below, where |
|
Or do you mean literally that the GC would happen 'right in the middle' such a call? Perhaps this is protected by the fact that the "reading" happens inside of this: I also remember pretty much copy pasting the whole structure from gecko when I worked on this :) (although perhaps not creating the blob just to return the pointer) |
|
Lastly, I remember reading through the actual implementation of |
|
Yes, there is no risk of GC happening randomly or in parallel. It can happen as a result of any new JS allocation or certain API calls. |
|
In Gecko, they actually seem to keep track of cloned Blobs with this nsTArray<RefPtr> mBlobImplArray, stored inside a So what they do is also 'creating a blob and then returning a pointer to it's raw JsObject', however they always keep the corresponding The In the callbacks, they write/read the index of a given Blob in the array using So perhaps we could store the Actually we might want to remove the callbacks from the 'regular' call to I guess the big question is where to put that |
Use a structured clone holder to store rooted clones <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #21164 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21218) <!-- Reviewable:end -->
This code creates a Blob, which is rooted in the current stack frame, then returns its reflector's JSObject pointer. This means that the blob object is no longer rooted, and depending on what the JS engine does with the return value of
read_callback, the pointer could be pointing at a DOM object that gets GCed by the time it's used. We should look carefully at what Firefox does here.