Closed
Bug 552516
Opened 14 years ago
Closed 14 years ago
avoiding temporary JSContext instance in xpc_CreateSandboxObject
Categories
(Core :: XPConnect, enhancement)
Core
XPConnect
Tracking
()
RESOLVED
FIXED
People
(Reporter: igor, Assigned: mrbkap)
Details
Attachments
(1 file, 1 obsolete file)
4.48 KB,
patch
|
mrbkap
:
review+
|
Details | Diff | Splinter Review |
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.
Assignee | ||
Comment 1•14 years ago
|
||
Sorry for jumping the gun here, igor, but I'm patching this code anyway right now and this patch was too tempting.
Reporter | ||
Comment 2•14 years ago
|
||
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+
Reporter | ||
Comment 3•14 years ago
|
||
(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.
Assignee | ||
Comment 4•14 years ago
|
||
Good catch!
Attachment #432971 -
Attachment is obsolete: true
Attachment #433120 -
Flags: review+
Assignee | ||
Comment 5•14 years ago
|
||
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
Assignee | ||
Comment 6•14 years ago
|
||
http://hg.mozilla.org/mozilla-central/rev/8a385caddbef
You need to log in
before you can comment on or make changes to this bug.
Description
•