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
116 lines (100 loc) · 3.32 KB

File metadata and controls

116 lines (100 loc) · 3.32 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "JsrtPch.h"
#include "JsrtRuntime.h"
#include "Base/ThreadContextTlsEntry.h"
static THREAD_LOCAL JsrtContext* s_tlvSlot = nullptr;
JsrtContext::JsrtContext(JsrtRuntime * runtime) :
runtime(runtime), javascriptLibrary(nullptr)
{
}
void JsrtContext::SetJavascriptLibrary(Js::JavascriptLibrary * library)
{
this->javascriptLibrary = library;
if (this->javascriptLibrary)
{
this->javascriptLibrary->SetJsrtContext(this);
}
}
void JsrtContext::Link()
{
// Link this new JsrtContext up in the JsrtRuntime's context list
this->next = runtime->contextList;
this->previous = nullptr;
if (runtime->contextList != nullptr)
{
Assert(runtime->contextList->previous == nullptr);
runtime->contextList->previous = this;
}
runtime->contextList = this;
}
void JsrtContext::Unlink()
{
// Unlink from JsrtRuntime JsrtContext list
if (this->previous == nullptr)
{
// Have to check this because if we failed while creating, it might
// never have gotten linked in to the runtime at all.
if (this->runtime->contextList == this)
{
this->runtime->contextList = this->next;
}
}
else
{
Assert(this->previous->next == this);
this->previous->next = this->next;
}
if (this->next != nullptr)
{
Assert(this->next->previous == this);
this->next->previous = this->previous;
}
}
/* static */
JsrtContext * JsrtContext::GetCurrent()
{
return s_tlvSlot;
}
/* static */
bool JsrtContext::TrySetCurrent(JsrtContext * context)
{
ThreadContext * threadContext;
//We are not pinning the context after SetCurrentContext, so if the context is not pinned
//it might be reclaimed half way during execution. In jsrtshell the runtime was optimized out
//at time of JsrtContext::Run by the compiler.
//The change is to pin the context at setconcurrentcontext, and unpin the previous one. In
//JsDisposeRuntime we'll reject if current context is active, so that will make sure all
//contexts are unpinned at time of JsDisposeRuntime.
if (context != nullptr)
{
threadContext = context->GetScriptContext()->GetThreadContext();
if (!ThreadContextTLSEntry::TrySetThreadContext(threadContext))
{
return false;
}
// no need to rootAddRef and Release for the same context
if (s_tlvSlot == context) return true;
threadContext->GetRecycler()->RootAddRef((LPVOID)context);
}
else
{
if (!ThreadContextTLSEntry::ClearThreadContext(true))
{
return false;
}
}
JsrtContext* originalContext = s_tlvSlot;
if (originalContext != nullptr)
{
originalContext->GetScriptContext()->GetRecycler()->RootRelease((LPVOID) originalContext);
}
s_tlvSlot = context;
return true;
}
void JsrtContext::Mark(Recycler * recycler)
{
AssertMsg(false, "Mark called on object that isn't TrackableObject");
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.