Closed Bug 969812 Opened 11 years ago Closed 11 years ago

Make JS_NewArrayObject take HandleValueArray argument

Categories

(Core :: JavaScript Engine, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla30

People

(Reporter: jonco, Assigned: jonco)

References

Details

Attachments

(2 files, 2 obsolete files)

Currently JS_NewArrayObject takes a length argument and a Value pointer which it roots.  We should convert this to take a HandleValueArray and remove the rooting.
Attached patch 1 - convert-new-array-object (obsolete) — Splinter Review
Initial patch to do this in the JS engine.  Splits JS_NewArrayObject in to a version which takes a length and doesn't initialize, and a version which takes the contents of the new array.
Convert occurrences in the browser.
Assignee: nobody → jcoppeard
So there a few places where we have an Sequence<JS::Value> which we use as the contents for creating an array, in: 

- MessagePort::PostMessageMoz()
- nsGlobalWindow::PostMessageMoz()
- WorkerPrivateParent<Derived>::PostMessageInternal()
- WorkerPrivate::PostMessageToParentInternal()

I don't understand the control flow here, but it seems these are ultimately coming from generated bindings code which ensures they are rooted (hence I used fromMarkedLocation to convert them to a HandleValueArray).

Do you think this is ok, or is there some other source for these where they can be unrooted?

I was wondering about the possibility of changing these APIs to express the rooted-ness of the arguments but it seems like that would require special casing the bindings generation to sometimes generate flat arrays of Values in a different way.
Flags: needinfo?(bzbarsky)
Comment on attachment 8372858 [details] [diff] [review]
1 - convert-new-array-object

Review of attachment 8372858 [details] [diff] [review]:
-----------------------------------------------------------------

::: js/src/jsapi.cpp
@@ +3790,5 @@
> +    JS_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment()));
> +    AssertHeapIsIdle(cx);
> +    CHECK_REQUEST(cx);
> +
> +    return NewDenseCopiedArray(cx, length, nullptr);

I don't really understand all the different NewArray functions anymore, but NewDenseAllocatedArray seems like a better fit here.
> Do you think this is ok, or is there some other source for these where they can be
> unrooted?

No, they should always be coming from bindings code, and that should always root them.

> it seems like that would require special casing the bindings generation to sometimes
> generate flat arrays of Values in a different way

We can do that, if that would make things clearer.
Flags: needinfo?(bzbarsky)
(In reply to Boris Zbarsky [:bz] from comment #5)

Thanks.  I will leave it using fromMarkedLocation() for now then, but if these methods could take HandleValueArray then that would be clearer, and safer in case any anything else tries to call them.
Attachment #8372858 - Attachment is obsolete: true
Attachment #8374040 - Flags: review?(terrence)
Attachment #8373282 - Attachment is obsolete: true
Attachment #8374041 - Flags: review?(bzbarsky)
> but if these methods could take HandleValueArray

Please file a followup?  I'll look into how sane that is to do.
Comment on attachment 8374040 [details] [diff] [review]
1 - convert-new-array-object

Review of attachment 8374040 [details] [diff] [review]:
-----------------------------------------------------------------

Very nice! r=me
Attachment #8374040 - Flags: review?(terrence) → review+
Comment on attachment 8374041 [details] [diff] [review]
2 - convert-new-array-object-browser

>+++ b/dom/base/MessagePort.cpp
> MessagePort::PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,

Please don't add the stray blank line at the start of this function.

r=me with that
Attachment #8374041 - Flags: review?(bzbarsky) → review+
https://hg.mozilla.org/integration/mozilla-inbound/rev/33f464080abc
https://hg.mozilla.org/mozilla-central/rev/33f464080abc
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla30
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: