コード例 #1
0
ファイル: Js.cpp プロジェクト: sugarontop/D2DWindow
JsErrorCode CreateHostContext(JsRuntimeHandle runtime, int argc, wchar_t *argv [], int argumentsStart, JsContextRef *context)
{	
	JsCreateContext(runtime, context);
	
	JsSetCurrentContext(*context);

	
	JsValueRef hostObject;
	JsCreateObject(&hostObject);
	ghostObject = hostObject;

	JsValueRef globalObject;
	JsGetGlobalObject(&globalObject);
	
	JsPropertyIdRef hostPropertyId;
	JsGetPropertyIdFromName(L"app", &hostPropertyId); // app.XXXXX 

	JsSetProperty(globalObject, hostPropertyId, hostObject, true);

	//IfFailRet(DefineHostCallback(hostObject, L"msgbox", msgbox, nullptr));

	JsSetCurrentContext(JS_INVALID_REFERENCE);

	return JsNoError;
}
コード例 #2
0
ファイル: Js.cpp プロジェクト: sugarontop/D2DWindow
void RegistFunction( LPCWSTR function_name, JSFUNCTION func )
{
	JsSetCurrentContext(jscontext);

	IfFailRet(DefineHostCallback(ghostObject, function_name, func, nullptr));

	JsSetCurrentContext(JS_INVALID_REFERENCE);
}
コード例 #3
0
JsErrorCode ChakraHost::Destroy()
{
    IfFailRet(JsSetCurrentContext(JS_INVALID_REFERENCE));
    IfFailRet(JsDisposeRuntime(runtime));

    return JsNoError;
}
コード例 #4
0
ファイル: Js.cpp プロジェクト: sugarontop/D2DWindow
void JsAppClose()
{
	if ( runtime )
	{		
		JsCollectGarbage(runtime);		
		JsSetCurrentContext(JS_INVALID_REFERENCE);
		JsDisposeRuntime(runtime);		
		runtime = nullptr;
	}
}
コード例 #5
0
    void BasicTest(JsRuntimeAttributes attributes, LPCSTR fileName)
    {
        LPCWSTR script = nullptr;
        REQUIRE(FileLoadHelpers::LoadScriptFromFile(fileName, script) == S_OK);
        REQUIRE(script != nullptr);

        // Create the runtime
        JsRuntimeHandle runtime = JS_INVALID_RUNTIME_HANDLE;
        REQUIRE(JsCreateRuntime(attributes, nullptr, &runtime) == JsNoError);

        // Set memory limit
        REQUIRE(JsSetRuntimeMemoryLimit(runtime, MemoryLimit) == JsNoError);

        size_t memoryLimit;
        size_t memoryUsage;

        REQUIRE(JsGetRuntimeMemoryLimit(runtime, &memoryLimit) == JsNoError);
        CHECK(memoryLimit == MemoryLimit);
        REQUIRE(JsGetRuntimeMemoryUsage(runtime, &memoryUsage) == JsNoError);
        CHECK(memoryUsage < MemoryLimit);

        // Create and initialize the script context
        JsContextRef context = JS_INVALID_RUNTIME_HANDLE;
        REQUIRE(JsCreateContext(runtime, &context) == JsNoError);
        REQUIRE(JsSetCurrentContext(context) == JsNoError);

        // Invoke the script
        REQUIRE(JsRunScript(script, JS_SOURCE_CONTEXT_NONE, _u(""), nullptr) == JsErrorScriptException);

        ValidateOOMException();

        REQUIRE(JsGetRuntimeMemoryLimit(runtime, &memoryLimit) == JsNoError);
        CHECK(memoryLimit == MemoryLimit);
        REQUIRE(JsGetRuntimeMemoryUsage(runtime, &memoryUsage) == JsNoError);
        CHECK(memoryUsage <= MemoryLimit);

        // Destroy the runtime
        REQUIRE(JsSetCurrentContext(JS_INVALID_REFERENCE) == JsNoError);
        REQUIRE(JsCollectGarbage(runtime) == JsNoError);
        REQUIRE(JsDisposeRuntime(runtime) == JsNoError);
    }
コード例 #6
0
    bool TestCleanup(JsRuntimeHandle runtime)
    {
        if (runtime != nullptr)
        {
            // Disable debugging
            JsDiagStopDebugging(runtime, nullptr);

            JsSetCurrentContext(nullptr);
            JsDisposeRuntime(runtime);
        }
        return true;
    }
コード例 #7
0
ファイル: Js.cpp プロジェクト: sugarontop/D2DWindow
static JsContextRef AppInit()
{
	JsContextRef context;
	int argc = 1;
	WCHAR* argv[1];
	argv[0] = L"dumy";
	
	JsCreateRuntime(JsRuntimeAttributeNone, nullptr, &runtime);
	CreateHostContext(runtime, argc,argv,1,&context);

	JsSetCurrentContext(context);


	return context;
}
コード例 #8
0
JsErrorCode ChakraHost::Init()
{
    currentSourceContext = 0;

    IfFailRet(JsCreateRuntime(JsRuntimeAttributeNone, nullptr, &runtime));
    IfFailRet(JsCreateContext(runtime, &context));
    IfFailRet(JsSetCurrentContext(context));

    IfFailRet(JsGetGlobalObject(&globalObject));

    IfFailRet(InitJson());
    IfFailRet(InitConsole());

    return JsNoError;
}
コード例 #9
0
ファイル: Js.cpp プロジェクト: sugarontop/D2DWindow
CJsValueRef JsRun(LPCWSTR script)
{
	JsValueRef result;

	JsSetCurrentContext(jscontext);
	
	JsErrorCode errorCode = JsRunScript(script, currentSourceContext++, L"", &result);


	if ( JsNoError != errorCode )
	{
		throw errorCode;
	}

	return CJsValueRef(result);
}
コード例 #10
0
    void BreakpointsContextTest(JsRuntimeHandle runtime)
    {
        JsContextRef context = JS_INVALID_REFERENCE;
        REQUIRE(JsGetCurrentContext(&context) == JsNoError);

        // Verify no errors with a context set
        JsValueRef scriptsArray = JS_INVALID_REFERENCE;
        REQUIRE(JsDiagGetScripts(&scriptsArray) == JsNoError);

        // Verify the APIs return an error when no current context set
        JsSetCurrentContext(nullptr);
        CHECK(JsDiagGetScripts(&scriptsArray) == JsErrorNoCurrentContext);

        JsValueRef breakpoint = JS_INVALID_REFERENCE;
        CHECK(JsDiagSetBreakpoint(0, 0, 0, &breakpoint) == JsErrorNoCurrentContext);

        CHECK(JsDiagRemoveBreakpoint(0) == JsErrorNoCurrentContext);
    }