Skip to content

Instantly share code, notes, and snippets.

@benjamn
Created May 25, 2010 23:10
Show Gist options
  • Save benjamn/413807 to your computer and use it in GitHub Desktop.
Save benjamn/413807 to your computer and use it in GitHub Desktop.
bool
JetpackChild::Init(base::ProcessHandle aParentProcessHandle,
MessageLoop* aIOLoop,
IPC::Channel* aChannel)
{
if (!Open(aChannel, aParentProcessHandle, aIOLoop))
return false;
if (!(mRuntime = JS_NewRuntime(32L * 1024L * 1024L)) ||
!(mImplCx = JS_NewContext(mRuntime, 8192)) ||
!(mUserCx = JS_NewContext(mRuntime, 8192)))
return false;
{
JSAutoRequest request(mImplCx);
JS_SetContextPrivate(mImplCx, this);
JSObject* implGlobal = JS_NewObject(mImplCx, NULL, NULL, NULL);
JS_SetGlobalObject(mImplCx, implGlobal);
if (!implGlobal ||
!JS_InitStandardClasses(mImplCx, implGlobal) ||
!JS_DefineProperties(mImplCx, implGlobal,
const_cast<JSPropertySpec*>(sImplProperties)) ||
!JS_DefineFunctions(mImplCx, implGlobal,
const_cast<JSFunctionSpec*>(sImplMethods)))
return false;
}
{
JSAutoRequest request(mUserCx);
JS_SetContextPrivate(mUserCx, this);
JSObject* userGlobal = JS_NewObject(mUserCx, NULL, NULL, NULL);
JS_SetGlobalObject(mUserCx, userGlobal);
if (!userGlobal ||
!JS_InitStandardClasses(mUserCx, userGlobal))
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment