From 407857cbf96c0ff534d2168c0eac4d309980c945 Mon Sep 17 00:00:00 2001 From: Matheus Marchini Date: Thu, 3 Oct 2019 10:02:39 -0700 Subject: [PATCH] src: use Check() instead of raw != -1 a501635516aa0c153b1e17b62e47150b6458af99 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. --- src/llv8.cc | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/llv8.cc b/src/llv8.cc index 4c453cfd..f7c26e32 100644 --- a/src/llv8.cc +++ b/src/llv8.cc @@ -280,19 +280,17 @@ Smi JSFrame::FromFrameMarker(Value value) const { } std::string JSFunction::GetDebugLine(std::string args, Error& err) { - SharedFunctionInfo info = Info(err); - if (err.Fail()) return std::string(); + RETURN_IF_THIS_INVALID(std::string()); - std::string res = info.ProperName(err); + // TODO(mmarchini) turn this into CheckedType + std::string res = Name(err); if (err.Fail()) return std::string(); if (!args.empty()) res += "(" + args + ")"; res += " at "; - std::string shared; - - res += info.GetPostfix(err); + res += Info(err).GetPostfix(err); if (err.Fail()) return std::string(); return res; @@ -361,13 +359,15 @@ std::string JSFunction::GetSource(Error& err) { std::string SharedFunctionInfo::ProperName(Error& err) { + RETURN_IF_THIS_INVALID(std::string()); + String name = Name(err); if (err.Fail()) return std::string(); std::string res = name.ToString(err); if (err.Fail() || res.empty()) { Value inferred = GetInferredName(err); - if (err.Fail() || inferred.raw() == -1) return std::string(); + if (err.Fail() || !inferred.Check()) return std::string(); // Function may not have inferred name if (!inferred.IsHoleOrUndefined(err) && !err.Fail()) @@ -382,8 +382,10 @@ std::string SharedFunctionInfo::ProperName(Error& err) { std::string SharedFunctionInfo::GetPostfix(Error& err) { + RETURN_IF_THIS_INVALID(std::string()); + Script script = GetScript(err); - if (err.Fail() || script.raw() == -1) return std::string(); + if (err.Fail() || !script.Check()) return std::string(); // There is no `Script` for functions created in C++ (and possibly others) int64_t type = script.GetType(err); @@ -1233,9 +1235,11 @@ bool JSError::HasStackTrace(Error& err) { JSArray JSError::GetFrameArray(Error& err) { + RETURN_IF_THIS_INVALID(JSArray()); + v8::Value maybe_stack = GetProperty(stack_trace_property(), err); - if (err.Fail() || maybe_stack.raw() == -1) { + if (err.Fail() || !maybe_stack.Check()) { PRINT_DEBUG("Couldn't find a symbol property in the Error object."); return JSArray(); }