Skip to content

Commit 37b3c26

Browse files
committed
src: use Check() instead of raw != -1
a501635 changed the behavior of Check() so that it could be properly used to determine if an object was loaded successfully from memory. In the past we used raw != -1 to perform the same check. Some places were still using the old approach, which has less guarantees than Check(). This commit changes those places to use the new approach. Also added a few RETURN_IF_THIS_INVALID guards on the functions touched by this commit. PR-URL: #313 Reviewed-By: Colin Ihrig <[email protected]>
1 parent fde0c59 commit 37b3c26

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/llv8.cc

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -304,19 +304,17 @@ bool JSFrame::MightBeV8Frame(lldb::SBFrame& frame) {
304304
}
305305

306306
std::string JSFunction::GetDebugLine(std::string args, Error& err) {
307-
SharedFunctionInfo info = Info(err);
308-
if (err.Fail()) return std::string();
307+
RETURN_IF_THIS_INVALID(std::string());
309308

310-
std::string res = info.ProperName(err);
309+
// TODO(mmarchini) turn this into CheckedType
310+
std::string res = Name(err);
311311
if (err.Fail()) return std::string();
312312

313313
if (!args.empty()) res += "(" + args + ")";
314314

315315
res += " at ";
316316

317-
std::string shared;
318-
319-
res += info.GetPostfix(err);
317+
res += Info(err).GetPostfix(err);
320318
if (err.Fail()) return std::string();
321319

322320
return res;
@@ -385,13 +383,15 @@ std::string JSFunction::GetSource(Error& err) {
385383

386384

387385
std::string SharedFunctionInfo::ProperName(Error& err) {
386+
RETURN_IF_THIS_INVALID(std::string());
387+
388388
String name = Name(err);
389389
if (err.Fail()) return std::string();
390390

391391
std::string res = name.ToString(err);
392392
if (err.Fail() || res.empty()) {
393393
Value inferred = GetInferredName(err);
394-
if (err.Fail() || inferred.raw() == -1) return std::string();
394+
if (err.Fail() || !inferred.Check()) return std::string();
395395

396396
// Function may not have inferred name
397397
if (!inferred.IsHoleOrUndefined(err) && !err.Fail())
@@ -406,8 +406,10 @@ std::string SharedFunctionInfo::ProperName(Error& err) {
406406

407407

408408
std::string SharedFunctionInfo::GetPostfix(Error& err) {
409+
RETURN_IF_THIS_INVALID(std::string());
410+
409411
Script script = GetScript(err);
410-
if (err.Fail() || script.raw() == -1) return std::string();
412+
if (err.Fail() || !script.Check()) return std::string();
411413

412414
// There is no `Script` for functions created in C++ (and possibly others)
413415
int64_t type = script.GetType(err);
@@ -1257,9 +1259,11 @@ bool JSError::HasStackTrace(Error& err) {
12571259

12581260

12591261
JSArray JSError::GetFrameArray(Error& err) {
1262+
RETURN_IF_THIS_INVALID(JSArray());
1263+
12601264
v8::Value maybe_stack = GetProperty(stack_trace_property(), err);
12611265

1262-
if (err.Fail() || maybe_stack.raw() == -1) {
1266+
if (err.Fail() || !maybe_stack.Check()) {
12631267
PRINT_DEBUG("Couldn't find a symbol property in the Error object.");
12641268
return JSArray();
12651269
}

0 commit comments

Comments
 (0)