Closed Bug 552516 Opened 14 years ago Closed 14 years ago

avoiding temporary JSContext instance in xpc_CreateSandboxObject

Categories

(Core :: XPConnect, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: igor, Assigned: mrbkap)

Details

Attachments

(1 file, 1 obsolete file)

Currently xpc_CreateSandboxObject from js/src/xpconnect/src/xpccomponents.cpp contains the following code:

    XPCAutoJSContext tempcx(JS_NewContext(JS_GetRuntime(cx), 1024), PR_FALSE);
    if (!tempcx)
        return NS_ERROR_OUT_OF_MEMORY;

    JSAutoRequest req(tempcx);
    JSObject *sandbox = JS_NewObject(tempcx, &SandboxClass, nsnull, nsnull);
    if (!sandbox)
        return NS_ERROR_XPC_UNEXPECTED;

    JS_SetGlobalObject(tempcx, sandbox);

with no more references to tempcx. Thus the only purpose of the temporary context is to create the sandbox object with null proto and parent and to root it via setting the global object for tempcx to it. This can be replaced with JS_NewObjectWithGivenProto on the original cx and using one of autoroots to hold the result.
Attached patch Patch (obsolete) — Splinter Review
Sorry for jumping the gun here, igor, but I'm patching this code anyway right now and this patch was too tempting.
Assignee: igor → mrbkap
Status: NEW → ASSIGNED
Attachment #432971 - Flags: review?(igor)
Comment on attachment 432971 [details] [diff] [review]
Patch

>-    XPCAutoJSContext tempcx(JS_NewContext(JS_GetRuntime(cx), 1024), PR_FALSE);
>-    if (!tempcx)
>-        return NS_ERROR_OUT_OF_MEMORY;

With this change XPCAutoJSContext is only used for ContextHolder. So as a bonus that can be removed and the corresponding code just trivially inlined in the ContextHolder class.
Attachment #432971 - Flags: review?(igor) → review+
(In reply to comment #2)
> (From update of attachment 432971 [details] [diff] [review])
> >-    XPCAutoJSContext tempcx(JS_NewContext(JS_GetRuntime(cx), 1024), PR_FALSE);
> >-    if (!tempcx)
> >-        return NS_ERROR_OUT_OF_MEMORY;
> 
> With this change XPCAutoJSContext is only used for ContextHolder. So as a bonus
> that can be removed and the corresponding code just trivially inlined in the
> ContextHolder class.

I meant that the XPCAutoJSContext class can be removed.
Attached patch With thatSplinter Review
Good catch!
Attachment #432971 - Attachment is obsolete: true
Attachment #433120 - Flags: review+
I'll try to check this in, but if a checkin-needed fairy has time when the tree is open, then I'd welcome help.
Keywords: checkin-needed
http://hg.mozilla.org/mozilla-central/rev/8a385caddbef
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Keywords: checkin-needed
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: