Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
94 lines (71 loc) · 3.14 KB

File metadata and controls

94 lines (71 loc) · 3.14 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "stdafx.h"
#pragma warning(disable:26434) // Function definition hides non-virtual function in base class
#pragma warning(disable:26439) // Implicit noexcept
#pragma warning(disable:26451) // Arithmetic overflow
#pragma warning(disable:26495) // Uninitialized member variable
#include "catch.hpp"
#pragma warning(disable:6387) // suppressing preFAST which raises warning for passing null to the JsRT APIs
namespace ThreadServiceTests
{
struct ThreadPoolCallbackContext
{
JsBackgroundWorkItemCallback callback;
void * callbackData;
};
static bool sawCallback = false;
void CALLBACK ThreadPoolCallback(PTP_CALLBACK_INSTANCE /* Instance */, void * Context)
{
ThreadPoolCallbackContext * c = (ThreadPoolCallbackContext *)Context;
c->callback(c->callbackData);
delete c;
}
bool CALLBACK SubmitBackgroundWorkToThreadPool(JsBackgroundWorkItemCallback callback, void * callbackData)
{
REQUIRE(callback != nullptr);
REQUIRE(callbackData != nullptr);
sawCallback = true;
ThreadPoolCallbackContext * c = new ThreadPoolCallbackContext();
c->callback = callback;
c->callbackData = callbackData;
BOOL success = TrySubmitThreadpoolCallback(ThreadPoolCallback, c, nullptr);
REQUIRE(!!success);
return true;
}
bool CALLBACK FailBackgroundWorkRequest(JsBackgroundWorkItemCallback callback, void * callbackData)
{
REQUIRE(callback != nullptr);
REQUIRE(callbackData != nullptr);
sawCallback = true;
// Always fail the request and force work in-thread
return false;
}
void Test(JsThreadServiceCallback threadService)
{
sawCallback = false;
JsRuntimeHandle runtime = JS_INVALID_RUNTIME_HANDLE;
JsContextRef context = JS_INVALID_REFERENCE;
REQUIRE(JsCreateRuntime(JsRuntimeAttributeAllowScriptInterrupt, threadService, &runtime) == JsNoError);
REQUIRE(JsCreateContext(runtime, &context) == JsNoError);
REQUIRE(JsSetCurrentContext(context) == JsNoError);
LPCWSTR script = nullptr;
REQUIRE(FileLoadHelpers::LoadScriptFromFile("Splay.js", script) == S_OK);
REQUIRE(script != nullptr);
REQUIRE(JsRunScript(script, JS_SOURCE_CONTEXT_NONE, _u(""), nullptr) == JsNoError);
REQUIRE(JsSetCurrentContext(JS_INVALID_REFERENCE) == JsNoError);
REQUIRE(JsDisposeRuntime(runtime) == JsNoError);
// Ensure that at least one callback happened
CHECK(sawCallback);
}
TEST_CASE("ThreadServiceTest_ThreadPoolTest", "[ThreadServiceTest]")
{
Test(SubmitBackgroundWorkToThreadPool);
}
TEST_CASE("ThreadServiceTest_AlwaysDenyRequestTest", "[ThreadServiceTest]")
{
Test(FailBackgroundWorkRequest);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.