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
121 lines (102 loc) · 3.57 KB

File metadata and controls

121 lines (102 loc) · 3.57 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
117
118
119
120
121
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#ifdef HERMES_ENABLE_DEBUGGER
#include <gtest/gtest.h>
#include <hermes/DebuggerAPI.h>
#include <hermes/hermes.h>
#include <memory>
using namespace facebook::hermes;
using namespace facebook::hermes::debugger;
struct TestEventObserver : public debugger::EventObserver {
std::vector<PauseReason> pauseReasons;
std::vector<StackTrace> stackTraces;
Command didPause(Debugger &debugger) override {
pauseReasons.push_back(debugger.getProgramState().getPauseReason());
stackTraces.push_back(debugger.getProgramState().getStackTrace());
return Command::continueExecution();
}
};
struct DebuggerAPITest : public ::testing::Test {
void eval(const std::string &code) {
rt->global().getPropertyAsFunction(*rt, "eval").call(*rt, code);
}
std::shared_ptr<HermesRuntime> rt;
TestEventObserver observer;
DebuggerAPITest() : rt(makeHermesRuntime()) {
rt->getDebugger().setEventObserver(&observer);
}
};
TEST_F(DebuggerAPITest, SetAgentTest) {
// A basic test that exercises setting the debugger event observer by virtue
// of running the DebuggerAPITest constructor.
}
TEST_F(DebuggerAPITest, BasicPauseTest) {
// Test that a basic Pause scenario works.
eval("var x = 5; debugger; x=8; debugger;");
EXPECT_EQ(
std::vector<PauseReason>(
{PauseReason::DebuggerStatement, PauseReason::DebuggerStatement}),
observer.pauseReasons);
}
TEST_F(DebuggerAPITest, SingleFrameStackTraceTest) {
using namespace facebook;
rt->getDebugger().setPauseOnThrowMode(PauseOnThrowMode::All);
jsi::Function nativeThrower = jsi::Function::createFromHostFunction(
*rt,
jsi::PropNameID::forAscii(*rt, "nativeThrower"),
0,
[](jsi::Runtime &rt,
const jsi::Value &thisVal,
const jsi::Value *args,
size_t count) -> jsi::Value {
throw jsi::JSINativeException("NativeException");
});
rt->global().setProperty(*rt, "nativeThrower", nativeThrower);
jsi::Function caller = jsi::Function::createFromHostFunction(
*rt,
jsi::PropNameID::forAscii(*rt, "caller"),
0,
[](jsi::Runtime &rt,
const jsi::Value &thisVal,
const jsi::Value *args,
size_t count) -> jsi::Value {
jsi::Function jsThrower =
rt.global().getPropertyAsFunction(rt, "jsThrower");
return jsThrower.call(rt);
});
rt->global().setProperty(*rt, "caller", caller);
eval(
"globalThis.jsThrower = function jsThrower() { throw 1; };\n"
"globalThis.tester = function tester() {"
" try { throw 2; }"
" catch (e) { caller(); } };"
"");
jsi::Function tester =
rt->global().getProperty(*rt, "tester").asObject(*rt).asFunction(*rt);
try {
tester.call(*rt);
} catch (jsi::JSIException &) {
try {
tester.call(*rt);
} catch (jsi::JSError &err) {
EXPECT_EQ(1, err.value().getNumber());
}
}
ASSERT_EQ(
std::vector<PauseReason>({PauseReason::Exception,
PauseReason::Exception,
PauseReason::Exception}),
observer.pauseReasons);
ASSERT_EQ(3, observer.stackTraces[2].callFrameCount());
ASSERT_EQ(
"jsThrower", observer.stackTraces[2].callFrameForIndex(0).functionName);
ASSERT_EQ(
"(native)", observer.stackTraces[2].callFrameForIndex(1).functionName);
ASSERT_EQ(
"tester", observer.stackTraces[2].callFrameForIndex(2).functionName);
}
#endif
Morty Proxy This is a proxified and sanitized view of the page, visit original site.