From 1b8f143369234eb101959a868f9de61c76df9163 Mon Sep 17 00:00:00 2001 From: Matheus Marchini Date: Tue, 8 Oct 2019 16:34:05 -0700 Subject: [PATCH] src: make Symbol more resilient Instead of crashing if llnode fails to parse a Symbol, just return a ??? token. PR-URL: https://github.com/nodejs/llnode/pull/330 Reviewed-By: Gireesh Punathil Reviewed-By: Michael Dawson --- src/llv8-constants.cc | 2 +- src/llv8-constants.h | 2 +- src/llv8-inl.h | 2 +- src/llv8.cc | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/llv8-constants.cc b/src/llv8-constants.cc index 752c72ca..6e86a3b0 100644 --- a/src/llv8-constants.cc +++ b/src/llv8-constants.cc @@ -550,7 +550,7 @@ void Frame::Load() { void Symbol::Load() { - kNameOffset = LoadConstant("class_Symbol__name__Object"); + kNameOffset = LoadConstant({"class_Symbol__name__Object"}); } diff --git a/src/llv8-constants.h b/src/llv8-constants.h index 9c31daf2..7d3775ec 100644 --- a/src/llv8-constants.h +++ b/src/llv8-constants.h @@ -509,7 +509,7 @@ class Symbol : public Module { public: CONSTANTS_DEFAULT_METHODS(Symbol); - int64_t kNameOffset; + Constant kNameOffset; protected: void Load(); diff --git a/src/llv8-inl.h b/src/llv8-inl.h index 53e90b4b..ad93e978 100644 --- a/src/llv8-inl.h +++ b/src/llv8-inl.h @@ -281,7 +281,7 @@ ACCESSOR(Map, MaybeConstructor, map()->kMaybeConstructorOffset, HeapObject) SAFE_ACCESSOR(Map, InstanceDescriptors, map()->kInstanceDescriptorsOffset, HeapObject) -ACCESSOR(Symbol, Name, symbol()->kNameOffset, HeapObject) +SAFE_ACCESSOR(Symbol, Name, symbol()->kNameOffset, HeapObject) inline int64_t Map::BitField3(Error& err) { return v8()->LoadUnsigned(LeaField(v8()->map()->kBitField3Offset), 4, err); diff --git a/src/llv8.cc b/src/llv8.cc index 5d316271..f70e18e5 100644 --- a/src/llv8.cc +++ b/src/llv8.cc @@ -729,6 +729,7 @@ std::string Symbol::ToString(Error& err) { return "Symbol()"; } HeapObject name = Name(err); + RETURN_IF_INVALID(name, "Symbol(???)"); return "Symbol('" + String(name).ToString(err) + "')"; }