mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 820170 - SandboxPrivate for jsd global. r=bholley
This commit is contained in:
parent
76d19a29d3
commit
5c25d885ea
@ -37,10 +37,23 @@ void JSD_ASSERT_VALID_CONTEXT(JSDContext* jsdc)
|
||||
}
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
/* xpconnect related utility functions implemented in jsd_xpc.cpp */
|
||||
|
||||
extern void
|
||||
global_finalize(JSFreeOp* fop, JSObject* obj);
|
||||
|
||||
extern JSObject*
|
||||
CreateJSDGlobal(JSContext *cx, JSClass *clasp);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
static JSClass global_class = {
|
||||
"JSDGlobal", JSCLASS_GLOBAL_FLAGS,
|
||||
"JSDGlobal", JSCLASS_GLOBAL_FLAGS |
|
||||
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, global_finalize
|
||||
};
|
||||
|
||||
static JSBool
|
||||
@ -108,7 +121,7 @@ _newJSDContext(JSRuntime* jsrt,
|
||||
JS_BeginRequest(jsdc->dumbContext);
|
||||
JS_SetOptions(jsdc->dumbContext, JS_GetOptions(jsdc->dumbContext));
|
||||
|
||||
jsdc->glob = JS_NewGlobalObject(jsdc->dumbContext, &global_class, NULL);
|
||||
jsdc->glob = CreateJSDGlobal(jsdc->dumbContext, &global_class);
|
||||
|
||||
if( ! jsdc->glob )
|
||||
goto label_newJSDContext_failure;
|
||||
|
@ -31,6 +31,8 @@
|
||||
/* XXX DOM dependency */
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIJSContextStack.h"
|
||||
#include "SandboxPrivate.h"
|
||||
#include "nsJSPrincipals.h"
|
||||
|
||||
/*
|
||||
* defining CAUTIOUS_SCRIPTHOOK makes jsds disable GC while calling out to the
|
||||
@ -3434,6 +3436,36 @@ static const mozilla::Module kJSDModule = {
|
||||
|
||||
NSMODULE_DEFN(JavaScript_Debugger) = &kJSDModule;
|
||||
|
||||
void
|
||||
global_finalize(JSFreeOp *aFop, JSObject *aObj)
|
||||
{
|
||||
nsIScriptObjectPrincipal *sop =
|
||||
static_cast<nsIScriptObjectPrincipal *>(js::GetObjectPrivate(aObj));
|
||||
MOZ_ASSERT(sop);
|
||||
static_cast<SandboxPrivate *>(sop)->ForgetGlobalObject();
|
||||
NS_IF_RELEASE(sop);
|
||||
}
|
||||
|
||||
JSObject *
|
||||
CreateJSDGlobal(JSContext *aCx, JSClass *aClasp)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPrincipal> nullPrin = do_CreateInstance("@mozilla.org/nullprincipal;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
JSPrincipals *jsPrin = nsJSPrincipals::get(nullPrin);
|
||||
JSObject *global = JS_NewGlobalObject(aCx, aClasp, jsPrin);
|
||||
NS_ENSURE_TRUE(global, nullptr);
|
||||
|
||||
// We have created a new global let's attach a private to it
|
||||
// that implements nsIGlobalObject.
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> sbp =
|
||||
new SandboxPrivate(nullPrin, global);
|
||||
JS_SetPrivate(global, sbp.forget().get());
|
||||
|
||||
return global;
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
********************************************************************************
|
||||
* graveyard
|
||||
|
Loading…
Reference in New Issue
Block a user