0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-01 20:25:12 -05:00

Prevent segfault when eval throws an error (#1411)

This commit is contained in:
Kevin (Kun) "Kassimo" Qian 2019-01-09 12:56:42 -08:00 committed by Ryan Dahl
parent 3634488caa
commit d835c84ba9
2 changed files with 22 additions and 4 deletions

View file

@ -99,10 +99,13 @@ std::string EncodeExceptionAsJSON(v8::Local<v8::Context> context,
CHECK(frame_obj
->Set(context, v8_str("functionName"), frame->GetFunctionName())
.FromJust());
CHECK(frame_obj
->Set(context, v8_str("scriptName"),
frame->GetScriptNameOrSourceURL())
.FromJust());
// scriptName can be empty in special conditions e.g. eval
auto scriptName = frame->GetScriptNameOrSourceURL();
if (scriptName.IsEmpty()) {
scriptName = v8_str("<unknown>");
}
CHECK(
frame_obj->Set(context, v8_str("scriptName"), scriptName).FromJust());
CHECK(frame_obj
->Set(context, v8_str("isEval"),
v8::Boolean::New(isolate, frame->IsEval()))

View file

@ -236,6 +236,21 @@ TEST(LibDenoTest, LastException) {
deno_delete(d);
}
TEST(LibDenoTest, EncodeErrorBug) {
Deno* d = deno_new(deno_config{0, empty, empty, nullptr, nullptr});
EXPECT_EQ(deno_last_exception(d), nullptr);
EXPECT_FALSE(deno_execute(d, nullptr, "a.js", "eval('a')"));
EXPECT_STREQ(deno_last_exception(d),
"{\"message\":\"ReferenceError: a is not defined\","
"\"frames\":[{\"line\":1,\"column\":1,"
"\"functionName\":\"\",\"scriptName\":\"<unknown>\","
"\"isEval\":true,"
"\"isConstructor\":false,\"isWasm\":false},{\"line\":1,"
"\"column\":1,\"functionName\":\"\",\"scriptName\":\"a.js\","
"\"isEval\":false,\"isConstructor\":false,\"isWasm\":false}]}");
deno_delete(d);
}
TEST(LibDenoTest, Shared) {
uint8_t s[] = {0, 1, 2};
deno_buf shared = {nullptr, 0, s, 3};