Esempio n. 1
0
/*
 * Class:     org_appcelerator_kroll_runtime_v8_V8Runtime
 * Method:    nativeInit
 * Signature: (Lorg/appcelerator/kroll/runtime/v8/V8Runtime;)J
 */
JNIEXPORT void JNICALL Java_org_appcelerator_kroll_runtime_v8_V8Runtime_nativeInit(JNIEnv *env, jobject self, jboolean useGlobalRefs, jobject debugger, jboolean DBG, jboolean profilerEnabled)
{
	if (!V8Runtime::initialized) {
		// Initialize V8.
		V8::InitializeICU();
		// TODO Enable this when we use snapshots?
		//V8::InitializeExternalStartupData(argv[0]);
		V8Runtime::platform = platform::CreateDefaultPlatform();
		V8::InitializePlatform(V8Runtime::platform);
		V8::Initialize();
		V8Runtime::initialized = true;
	}

	if (profilerEnabled) {
		char* argv[] = { const_cast<char*>(""), const_cast<char*>("--expose-gc") };
		int argc = sizeof(argv)/sizeof(*argv);
		V8::SetFlagsFromCommandLine(&argc, argv, false);
	}

	titanium::JNIScope jniScope(env);

	JavaObject::useGlobalRefs = useGlobalRefs;
	V8Runtime::DBG = DBG;

	V8Runtime::javaInstance = env->NewGlobalRef(self);
	JNIUtil::initCache();

	Isolate* isolate;
	if (V8Runtime::v8_isolate == nullptr) {
		// Create a new Isolate and make it the current one.
		Isolate::CreateParams create_params;
		create_params.array_buffer_allocator = &allocator;
		isolate = Isolate::New(create_params);
		isolate->Enter();

		V8Runtime::v8_isolate = isolate;

		// Log all uncaught V8 exceptions.
		V8::AddMessageListener(&logV8Exception);
		V8::SetCaptureStackTraceForUncaughtExceptions(true);
	} else {
		isolate = V8Runtime::v8_isolate;
		isolate->Enter();
	}

	HandleScope scope(isolate);
	Local<Context> context = Context::New(isolate);
	context->Enter();

	V8Runtime::globalContext.Reset(isolate, context);

	JSDebugger::init(env, isolate, debugger);
	if (debugger != nullptr) {
		V8Runtime::debuggerEnabled = true;
	}

	V8Runtime::bootstrap(context);

	LOG_HEAP_STATS(isolate, TAG);
}
Esempio n. 2
0
/*
 * Class:     org_appcelerator_kroll_runtime_v8_V8Runtime
 * Method:    nativeInit
 * Signature: (Lorg/appcelerator/kroll/runtime/v8/V8Runtime;)J
 */
JNIEXPORT void JNICALL Java_org_appcelerator_kroll_runtime_v8_V8Runtime_nativeInit(JNIEnv *env, jobject self, jboolean useGlobalRefs, jobject debugger, jboolean DBG, jboolean profilerEnabled)
{
	if (!V8Runtime::initialized) {
		// Initialize V8.
		V8::InitializeICU();

		// TODO Enable this when we use snapshots?
		//V8::InitializeExternalStartupData(argv[0]);
		V8Runtime::platform = platform::CreateDefaultPlatform();
		V8::InitializePlatform(V8Runtime::platform);
		V8::Initialize();
		V8Runtime::initialized = true;
	}

	titanium::JNIScope jniScope(env);

	JavaObject::useGlobalRefs = useGlobalRefs;
	V8Runtime::DBG = DBG;

	V8Runtime::javaInstance = env->NewGlobalRef(self);
	JNIUtil::initCache();

	Isolate* isolate;
	if (V8Runtime::v8_isolate == nullptr) {
		// Create a new Isolate and make it the current one.
		Isolate::CreateParams create_params;
		create_params.array_buffer_allocator = &allocator;
		isolate = Isolate::New(create_params);
		isolate->Enter();

		V8Runtime::v8_isolate = isolate;

		// Log all uncaught V8 exceptions.
		isolate->AddMessageListener(logV8Exception);
		// isolate->SetAbortOnUncaughtExceptionCallback(ShouldAbortOnUncaughtException);
		// isolate->SetAutorunMicrotasks(false);
		// isolate->SetFatalErrorHandler(OnFatalError);
		isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, v8::StackTrace::kOverview);
	} else {
		isolate = V8Runtime::v8_isolate;
		isolate->Enter();
	}

	HandleScope scope(isolate);
	Local<Context> context = Context::New(isolate);
	context->Enter();

	V8Runtime::globalContext.Reset(isolate, context);

	JSDebugger::init(env, debugger, context);
	if (debugger != nullptr) {
		V8Runtime::debuggerEnabled = true;
	}

	V8Runtime::bootstrap(context);

	LOG_HEAP_STATS(isolate, TAG);
}
	void enter(Local<Context> context)
	{
		context->Enter();
	}