Ejemplo 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);
}
Ejemplo 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);
}
Ejemplo n.º 3
0
Archivo: V8.cpp Proyecto: caivega/dukv8
bool V8::Initialize() {
    Isolate *isolate = Isolate::New();
    isolate->Enter();
    atexit([]() {
        Isolate::GetCurrent()->Dispose();
    });
    return true;
}
Ejemplo n.º 4
0
/*
 * Prototype:
 * Thread.sleep(delay)
 *
 * Docs:
 * TBW
 *
 * Example:
 * TBW
 */
static void
gum_script_thread_on_sleep (const FunctionCallbackInfo<Value> & info)
{
  Isolate * isolate = info.GetIsolate ();

  Local<Value> delay_val = info[0];
  if (!delay_val->IsNumber ())
  {
    isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate,
        "Thread.sleep: argument must be a number specifying delay")));
    return;
  }
  double delay = delay_val->ToNumber ()->Value ();

  isolate->Exit ();
  {
    Unlocker ul (isolate);
    g_usleep (delay * G_USEC_PER_SEC);
  }
  isolate->Enter ();
}