Last Comment Bug 783431 - Fix js array initialization for bluetooth and telephony
: Fix js array initialization for bluetooth and telephony
Product: Core
Classification: Components
Component: DOM: Device Interfaces (show other bugs)
: Trunk
: x86_64 Linux
-- normal (vote)
: mozilla17
Assigned To: Kyle Machulis [:qdot]
: Andrew Overholt [:overholt]
Depends on:
Blocks: b2g-ril b2g-bluetooth
  Show dependency treegraph
Reported: 2012-08-16 17:30 PDT by Kyle Machulis [:qdot]
Modified: 2012-08-21 06:28 PDT (History)
1 user (show)
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---

Patch 1 (v1): Fix js array initialization for bluetooth and telephony (2.93 KB, patch)
2012-08-20 15:22 PDT, Kyle Machulis [:qdot]
mrbkap: review+
Details | Diff | Splinter Review

Description User image Kyle Machulis [:qdot] 2012-08-16 17:30:17 PDT
from bug 777671:


::: dom/bluetooth/BluetoothUtils.cpp
@@ +82,5 @@
> +    arrayObj = JS_NewArrayObject(aCx, 0, nullptr);
> +  } else {
> +    uint32_t valLength = aSourceArray.Length();
> +    mozilla::ScopedDeleteArray<jsval> valArray(new jsval[valLength]);
> +    JS::AutoArrayRooter tvr(aCx, valLength, valArray);

I think this was copied from elsewhere, but there's a small problem. valArray's
elements are uninitialized, so if there's a GC during the loop, we'll mark a
bunch of uninitialized values. So, either we need to memset valArray to 0
(JSVAL_NULL) or pass 0 for the length and use changeLength(index + 1) each time
through the loop (see
.cpp#l5773 for an example).


This happens elsewhere in bt and telephony, so we should fix it everywhere. And really figure out something about centralizing these functions. :/
Comment 1 User image Blake Kaplan (:mrbkap) 2012-08-16 18:30:03 PDT
How about nsContentUtils or nsJSUtils?
Comment 2 User image Kyle Machulis [:qdot] 2012-08-16 18:57:40 PDT
bent was saying this got kicked out of ContentUtils for some reason? I'd be happy to have it there otherwise.
Comment 3 User image Kyle Machulis [:qdot] 2012-08-20 15:22:47 PDT
Created attachment 653546 [details] [diff] [review]
Patch 1 (v1): Fix js array initialization for bluetooth and telephony

Leaving functions where they are for the moment. Moving these to nsContentUtils would require templatizing, and there's nothing in there currently that does that. Would rather get these fixed and file followup where positional bikeshedding can happen.
Comment 5 User image Ed Morley [:emorley] 2012-08-21 06:28:51 PDT

Note You need to log in before you can comment on or make changes to this bug.