NS_ENSURE_TRUE(JS_GetProperty(ctx, object, "receiveMessage", &funval) with message manager and sandboxes

RESOLVED FIXED in mozilla8

Status

()

Core
IPC
RESOLVED FIXED
6 years ago
6 years ago

People

(Reporter: Felipe, Assigned: jdm)

Tracking

(Blocks: 1 bug)

unspecified
mozilla8
x86
All
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment, 1 obsolete attachment)

(Reporter)

Description

6 years ago
I've been trying to add mm listeners using the Scratchpad, but whenever a message is received, I get the following error and the listener is not called:

WARNING: NS_ENSURE_TRUE(JS_GetProperty(ctx, object, "receiveMessage", &funval) && JSVAL_IS_OBJECT(funval) && !JSVAL_IS_NULL(funval)) failed: file c:/moz/mozilla
-central/ff-debug/content/base/src/../../../../mozilla/content/base/src/nsFrameMessageManager.cpp, line 436


How to reproduce:
-----------------
set the pref devtools.chrome.enabled = true
Open Scratchpad (Shift + F4) and set Environment -> Browser

type this code in the text area, select all the text and choose Execute -> Run:

/***** begin *****/

gBrowser.selectedBrowser.messageManager.addMessageListener("z", function(o) {
  alert(o.json.q);
});

gBrowser.selectedBrowser.messageManager.loadFrameScript('data:,sendAsyncMessage("z", {q: "bar"})', false);

/***** end *****/


###########
What causes it is that the Scratchpad runs the code through a sandbox prototyped with the browser window.


The actual code boils down to:

/*** begin ***/
var mm = gBrowser.selectedBrowser.messageManager;
var win = Services.wm.getMostRecentWindow("navigator:browser");
var sand = new Cu.Sandbox(win, {sandboxPrototype:win});

var sandboxscript = "gBrowser.selectedBrowser.messageManager.addMessageListener('z', function(o) { alert(o.json.q);});"
Cu.evalInSandbox(sandboxscript, sand);
mm.loadFrameScript('data:,sendAsyncMessage("z", {q: "bar"})', false);

/*** end ***/
(Reporter)

Updated

6 years ago
Blocks: 667259
(Assignee)

Comment 1

6 years ago
Created attachment 548678 [details] [diff] [review]
Relax message listener restrictions to allow callable proxies.
Attachment #548678 - Flags: review?(Olli.Pettay)
(Assignee)

Updated

6 years ago
Assignee: nobody → josh
(Assignee)

Comment 2

6 years ago
Comment on attachment 548678 [details] [diff] [review]
Relax message listener restrictions to allow callable proxies.

There's nothing wrong with this patch, but I just noticed the other call to JS_IsObjectFunction in the other branch. We should probably nix that too, because I suspect that the current testcase with an object that has receiveMessage would probably fail similarly.
Attachment #548678 - Attachment is obsolete: true
Attachment #548678 - Flags: review?(Olli.Pettay)
(Assignee)

Comment 3

6 years ago
Created attachment 548880 [details] [diff] [review]
Relax message listener restrictions to allow callable proxies.
Attachment #548880 - Flags: review?(Olli.Pettay)

Updated

6 years ago
Attachment #548880 - Flags: review?(Olli.Pettay) → review+
(Reporter)

Comment 4

6 years ago
thanks Josh!
http://hg.mozilla.org/integration/mozilla-inbound/rev/3d3f25a67e24
Whiteboard: [inbound]
backed out for android reftest failures
Whiteboard: [inbound]
I think it has nothing to do with those failures, my suspect is that the Android ndk changes are causing them (mozilla central has same failures)
relanded
http://hg.mozilla.org/integration/mozilla-inbound/rev/c2ab7a1d1350
Whiteboard: [inbound]
This was backed out from inbound...
Whiteboard: [inbound]
it was not, I relanded it :)
http://hg.mozilla.org/mozilla-central/rev/c2ab7a1d1350
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla8
You need to log in before you can comment on or make changes to this bug.