Closed Bug 849730 Opened 7 years ago Closed 7 years ago

[Contacts] Make Array.isArray work for contacts

Categories

(Firefox OS Graveyard :: Gaia::Contacts, defect)

ARM
Gonk (Firefox OS)
defect
Not set

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: allstars.chh, Assigned: allstars.chh)

References

Details

Attachments

(2 files)

From Bug 842981, I found that Array.isArray check in 

https://github.com/mozilla-b2g/gaia/blob/master/apps/communications/contacts/js/utilities/import_sim_contacts.js#L40

will become false on m-c.

After some discussion with bholley (see Bug 842981),
he commented this is the correct behavior.

So I think for now, we should remove that isArray check in gaia,
otherwise "Import SIM Contacts" is broken now.

Hi Jose M Cantera,
Do you think we could remove the isArray check from your previous patch?

thanks
-1 to change that. Array.isArray should work properly otherwise the platform side is broken and should be fixed. 

thanks
CCing bholley and Gregor
I am not an expert from JS engine, hope bholley and Gregor could share more comments here.
(Also the changes to JS Engine is from Bug 809652, however I cannot access it).
(In reply to Jose M. Cantera from comment #1)
> -1 to change that. Array.isArray should work properly otherwise the platform
> side is broken and should be fixed. 
> 
> thanks

Hi, Jose

If you still think 'platfom side is broken', please re-open Bug 842981 and discuss that implementation detail with bholley.

Also from nsIDOMContactManager.idl, it doesn't define specifically the 'result' in DOMRequest is type of Array, in order to make your patch has more compatibility, I think we should remove Array.isArray check.

Array.isArray in your pevious patch could work on b2g18 because the code is programmed to 'implementation', not to interface.

How do you think?

Thanks
(In reply to Jose M. Cantera from comment #1)
> -1 to change that. Array.isArray should work properly otherwise the platform
> side is broken and should be fixed. 
> 
> thanks

The issue is that wrapped chrome JS-objects aren't actually a good way to expose DOM APIs, but in some of the rush to get B2G out the door we ended up doing that anyway.

We could special-case the objectClassIs to work for these kinds of wrappers if there's an associated __exposedProps__ or something like that. But this API is deprecated at this point, and we don't really want to alter the semantics for non-security reasons. Unless it's a big pain to change this in the contact manager, that's probably the path of least resistance.
ping? Jose M. Cantera
Attached file Pull Request
Assignee: nobody → allstars.chh
Comment on attachment 724415 [details]
Pull Request

Hi, Kaze 
Can you review this for me?

The background here is explained in comment 4 and Bug 842981 from bholley.

So in this patch I just removed Array.isArray check for the result returned from DOMRequest.

Thanks
Attachment #724415 - Flags: review?(kaze)
(In reply to Jose M. Cantera from comment #1)
> -1 to change that. Array.isArray should work properly otherwise the platform
> side is broken and should be fixed. 
> 
> thanks

I agree here.
This should be fixed with bug 850430 but I don't see this happening in the next few days. We can take this PR as a quick fix but I am worried that we have more bugs like this in gaia now.
If you think this is a significant source of potential regressions, I can hack the platform to make this work.
(In reply to Bobby Holley (:bholley) from comment #9)
> If you think this is a significant source of potential regressions, I can
> hack the platform to make this work.

Lets start with the behavior that changed and I can take a look if we have to fix more code.

So the current use-case we want to fix is an array that is created when we send the imported SIM contacts from the parent to the child via the parent/childprocessmessagemanager. I believe here we create the array somewhere in the message manager code in c++, modify the content in ContactManager.js and hand it out to content. So this stopped working.

How about an array that is created in JS chrome code and handed out to content? Does this still work? If I read your comment https://bugzilla.mozilla.org/show_bug.cgi?id=842981#c3 correctly it also stopped working. We might have more code that does this but I have to check.
(In reply to Gregor Wagner [:gwagner] from comment #10)
> How about an array that is created in JS chrome code and handed out to
> content? Does this still work? If I read your comment
> https://bugzilla.mozilla.org/show_bug.cgi?id=842981#c3 correctly it also
> stopped working. We might have more code that does this but I have to check.

That comment wasn't entirely accurate. In reality, there's a proxy hook called "objectClassIs" that will be invoked if we ever hit a cross-compartment wrapper. In bug 809652, I made that hook always return false for security wrappers, mostly as defense-in-depth. This runs up, yet again, into the fundamental problem we're having with COWs: they're security wrappers, and we need to protect the wrappee, but people expect them to be transparent like bonafide content objects.

I can make a special-case override for COWs in XPConnect that lets the ObjectClassIs trap through. It's kind of gross, but I think it should be ok security-wise so long as we commit to eventually moving contacts over to WebIDL. Shall I go ahead and do that?
(In reply to Bobby Holley (:bholley) from comment #11)
> 
> I can make a special-case override for COWs in XPConnect that lets the
> ObjectClassIs trap through. It's kind of gross, but I think it should be ok
> security-wise so long as we commit to eventually moving contacts over to
> WebIDL. Shall I go ahead and do that?


I think this would be the better workaround. We shouldn't change gaia code.
Reuben started working on the WebIDL implementation yesterday but I was already told that we might not have all the features we need in place right now. So it might take some time.
Thanks!
Summary: [Contacts] Remove Array.isArray check for the result from contacts.getSimContacts → [Contacts] Make Array.isArray work for contacts
Attachment #724524 - Flags: review?(mrbkap) → review+
https://hg.mozilla.org/mozilla-central/rev/030a2c329765
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.