forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsrtContextCore.cpp
More file actions
87 lines (71 loc) · 3.05 KB
/
JsrtContextCore.cpp
File metadata and controls
87 lines (71 loc) · 3.05 KB
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
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "Runtime.h"
#include "jsrtcontext.h"
#include "jsrtcontextcore.h"
JsrtContext *JsrtContext::New(JsrtRuntime * runtime)
{
return JsrtContextCore::New(runtime);
}
/* static */
bool JsrtContext::Is(void * ref)
{
return VirtualTableInfo<JsrtContextCore>::HasVirtualTable(ref);
}
void JsrtContext::OnScriptLoad(Js::JavascriptFunction * scriptFunction, Js::Utf8SourceInfo* utf8SourceInfo, CompileScriptException* compileException)
{
((JsrtContextCore *)this)->OnScriptLoad(scriptFunction, utf8SourceInfo, compileException);
}
JsrtContextCore::JsrtContextCore(JsrtRuntime * runtime) :
JsrtContext(runtime)
{
EnsureScriptContext();
Link();
PinCurrentJsrtContext();
}
/* static */
JsrtContextCore *JsrtContextCore::New(JsrtRuntime * runtime)
{
return RecyclerNewFinalizedLeaf(runtime->GetThreadContext()->EnsureRecycler(), JsrtContextCore, runtime);
}
void JsrtContextCore::Dispose(bool isShutdown)
{
if (nullptr != this->GetScriptContext())
{
if (this->GetRuntime()->GetDebugObject())
{
this->GetRuntime()->GetDebugObject()->ClearDebugDocument(this->GetScriptContext());
}
this->GetScriptContext()->EnsureClearDebugDocument();
this->GetScriptContext()->GetDebugContext()->GetProbeContainer()->UninstallInlineBreakpointProbe(NULL);
this->GetScriptContext()->GetDebugContext()->GetProbeContainer()->UninstallDebuggerScriptOptionCallback();
this->GetScriptContext()->MarkForClose();
this->SetScriptContext(nullptr);
Unlink();
}
}
Js::ScriptContext* JsrtContextCore::EnsureScriptContext()
{
Assert(this->GetScriptContext() == nullptr);
ThreadContext* localThreadContext = this->GetRuntime()->GetThreadContext();
AutoPtr<Js::ScriptContext> newScriptContext(Js::ScriptContext::New(localThreadContext));
newScriptContext->Initialize();
hostContext = HeapNew(ChakraCoreHostScriptContext, newScriptContext);
newScriptContext->SetHostScriptContext(hostContext);
this->SetScriptContext(newScriptContext.Detach());
Js::JavascriptLibrary *library = this->GetScriptContext()->GetLibrary();
Assert(library != nullptr);
library->GetEvalFunctionObject()->SetEntryPoint(&Js::GlobalObject::EntryEval);
library->GetFunctionConstructor()->SetEntryPoint(&Js::JavascriptFunction::NewInstance);
return this->GetScriptContext();
}
void JsrtContextCore::OnScriptLoad(Js::JavascriptFunction * scriptFunction, Js::Utf8SourceInfo* utf8SourceInfo, CompileScriptException* compileException)
{
JsrtDebug* debugObject = this->GetRuntime()->GetDebugObject();
if (debugObject != nullptr)
{
debugObject->ReportScriptCompile(scriptFunction, utf8SourceInfo, compileException);
}
}