forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeaveScriptObject.cpp
More file actions
93 lines (85 loc) · 3.31 KB
/
Copy pathLeaveScriptObject.cpp
File metadata and controls
93 lines (85 loc) · 3.31 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
88
89
90
91
92
93
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "RuntimeBasePch.h"
namespace Js
{
EnterScriptObject::EnterScriptObject(ScriptContext* scriptContext, ScriptEntryExitRecord* entryExitRecord,
void * returnAddress, void * addrOfReturnAddress, bool doCleanup, bool isCallRoot, bool hasCaller)
{
Assert(scriptContext);
#ifdef PROFILE_EXEC
scriptContext->ProfileBegin(Js::RunPhase);
#endif
if (scriptContext->GetThreadContext() &&
scriptContext->GetThreadContext()->IsNoScriptScope())
{
FromDOM_NoScriptScope_unrecoverable_error();
}
// Keep a copy locally so the optimizer can just copy prop it to the dtor
this->scriptContext = scriptContext;
this->entryExitRecord = entryExitRecord;
this->doCleanup = doCleanup;
this->isCallRoot = isCallRoot;
this->hr = NOERROR;
this->hasForcedEnter =
#ifdef ENABLE_SCRIPT_DEBUGGING
scriptContext->GetDebugContext() != nullptr ?
scriptContext->GetDebugContext()->GetProbeContainer()->isForcedToEnterScriptStart :
#endif
false;
// Initialize the entry exit record
entryExitRecord->returnAddrOfScriptEntryFunction = returnAddress;
entryExitRecord->addrOfReturnAddrOfScriptEntryFunction = addrOfReturnAddress;
entryExitRecord->hasCaller = hasCaller;
entryExitRecord->scriptContext = scriptContext;
#ifdef EXCEPTION_CHECK
entryExitRecord->handledExceptionType = ExceptionCheck::ClearHandledExceptionType();
#endif
#if DBG_DUMP
entryExitRecord->isCallRoot = isCallRoot;
#endif
if (!scriptContext->IsClosed())
{
library = scriptContext->GetLibrary();
}
try
{
AUTO_NESTED_HANDLED_EXCEPTION_TYPE(ExceptionType_OutOfMemory);
scriptContext->GetThreadContext()->PushHostScriptContext(scriptContext->GetHostScriptContext());
}
catch (Js::OutOfMemoryException)
{
this->hr = E_OUTOFMEMORY;
}
BEGIN_NO_EXCEPTION
{
// We can not have any exception in the constructor, otherwise the destructor will
// not run and we might be in an inconsistent state
// Put any code that may raise an exception in OnScriptStart
scriptContext->GetThreadContext()->EnterScriptStart(entryExitRecord, doCleanup);
}
END_NO_EXCEPTION
}
void EnterScriptObject::VerifyEnterScript()
{
if (FAILED(hr))
{
Assert(hr == E_OUTOFMEMORY);
throw Js::OutOfMemoryException();
}
}
EnterScriptObject::~EnterScriptObject()
{
scriptContext->OnScriptEnd(isCallRoot, hasForcedEnter);
if (SUCCEEDED(hr))
{
scriptContext->GetThreadContext()->PopHostScriptContext();
}
scriptContext->GetThreadContext()->EnterScriptEnd(entryExitRecord, doCleanup);
#ifdef PROFILE_EXEC
scriptContext->ProfileEnd(Js::RunPhase);
#endif
}
};