From 22588ccf93c549f526475325c3e59c66457d59f7 Mon Sep 17 00:00:00 2001 From: Matheus Marchini Date: Mon, 16 Jul 2018 10:17:56 -0300 Subject: [PATCH] src: fix JSError inspection This commit fixes JSError inspection for Node.js v7+. We still need to figure out a way to get the stack from the Error object though. Ref: https://github.com/nodejs/llnode/issues/143 --- src/llv8-constants.cc | 1 + src/llv8-constants.h | 1 + src/llv8-inl.h | 1 + test/fixtures/inspect-scenario.js | 4 ++++ test/plugin/inspect-test.js | 5 +++++ 5 files changed, 12 insertions(+) diff --git a/src/llv8-constants.cc b/src/llv8-constants.cc index 16d2eebb..4ab3b247 100644 --- a/src/llv8-constants.cc +++ b/src/llv8-constants.cc @@ -490,6 +490,7 @@ void Types::Load() { kFirstContextType = LoadConstant("FirstContextType"); kLastContextType = LoadConstant("LastContextType"); + kJSErrorType = LoadConstant("type_JSError__JS_ERROR_TYPE"); kHeapNumberType = LoadConstant("type_HeapNumber__HEAP_NUMBER_TYPE"); kMapType = LoadConstant("type_Map__MAP_TYPE"); kGlobalObjectType = diff --git a/src/llv8-constants.h b/src/llv8-constants.h index 80fc6e14..add69e88 100644 --- a/src/llv8-constants.h +++ b/src/llv8-constants.h @@ -478,6 +478,7 @@ class Types : public Module { int64_t kFirstContextType; int64_t kLastContextType; + int64_t kJSErrorType; int64_t kHeapNumberType; int64_t kMapType; int64_t kGlobalObjectType; diff --git a/src/llv8-inl.h b/src/llv8-inl.h index c49f5141..b4aeae69 100644 --- a/src/llv8-inl.h +++ b/src/llv8-inl.h @@ -211,6 +211,7 @@ ACCESSOR(JSObject, Elements, js_object()->kElementsOffset, HeapObject) inline bool JSObject::IsObjectType(LLV8* v8, int64_t type) { return type == v8->types()->kJSObjectType || type == v8->types()->kJSAPIObjectType || + type == v8->types()->kJSErrorType || type == v8->types()->kJSSpecialAPIObjectType; } diff --git a/test/fixtures/inspect-scenario.js b/test/fixtures/inspect-scenario.js index 11133acf..03a508a3 100644 --- a/test/fixtures/inspect-scenario.js +++ b/test/fixtures/inspect-scenario.js @@ -57,6 +57,10 @@ function closure() { ); c.hashmap['buffer'] = Buffer.from([0xff, 0xf0, 0x80, 0x0f, 0x01, 0x00]); + c.hashmap['error'] = new Error('test'); + c.hashmap['error'].code = 'ERR_TEST'; + c.hashmap['error'].errno = 1; + c.hashmap[0] = null; c.hashmap[4] = undefined; c.hashmap[23] = /regexp/; diff --git a/test/plugin/inspect-test.js b/test/plugin/inspect-test.js index 0d4dbcdb..d869ed51 100644 --- a/test/plugin/inspect-test.js +++ b/test/plugin/inspect-test.js @@ -133,6 +133,11 @@ const hashMapTests = { re: /.sliced-externalized-string=(0x[0-9a-f]+):/, desc: '.sliced-externalized-string Sliced ExternalString property' }, + // .error=0x0000392d5d661119: + 'error': { + re: /.error=(0x[0-9a-f]+):/, + desc: '.error Error property' + }, // .array=0x000003df9cbe7919:, 'array': { re: /.array=(0x[0-9a-f]+):/,