mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
Prevent segfault when eval throws an error (#1411)
This commit is contained in:
parent
3634488caa
commit
d835c84ba9
2 changed files with 22 additions and 4 deletions
|
@ -99,10 +99,13 @@ std::string EncodeExceptionAsJSON(v8::Local<v8::Context> context,
|
||||||
CHECK(frame_obj
|
CHECK(frame_obj
|
||||||
->Set(context, v8_str("functionName"), frame->GetFunctionName())
|
->Set(context, v8_str("functionName"), frame->GetFunctionName())
|
||||||
.FromJust());
|
.FromJust());
|
||||||
CHECK(frame_obj
|
// scriptName can be empty in special conditions e.g. eval
|
||||||
->Set(context, v8_str("scriptName"),
|
auto scriptName = frame->GetScriptNameOrSourceURL();
|
||||||
frame->GetScriptNameOrSourceURL())
|
if (scriptName.IsEmpty()) {
|
||||||
.FromJust());
|
scriptName = v8_str("<unknown>");
|
||||||
|
}
|
||||||
|
CHECK(
|
||||||
|
frame_obj->Set(context, v8_str("scriptName"), scriptName).FromJust());
|
||||||
CHECK(frame_obj
|
CHECK(frame_obj
|
||||||
->Set(context, v8_str("isEval"),
|
->Set(context, v8_str("isEval"),
|
||||||
v8::Boolean::New(isolate, frame->IsEval()))
|
v8::Boolean::New(isolate, frame->IsEval()))
|
||||||
|
|
|
@ -236,6 +236,21 @@ TEST(LibDenoTest, LastException) {
|
||||||
deno_delete(d);
|
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) {
|
TEST(LibDenoTest, Shared) {
|
||||||
uint8_t s[] = {0, 1, 2};
|
uint8_t s[] = {0, 1, 2};
|
||||||
deno_buf shared = {nullptr, 0, s, 3};
|
deno_buf shared = {nullptr, 0, s, 3};
|
||||||
|
|
Loading…
Add table
Reference in a new issue