From dd76fece6191c17d02446d2225a44c9540cfce17 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 PR-URL: https://github.com/nodejs/llnode/pull/215 Refs: https://github.com/nodejs/llnode/issues/143 Reviewed-By: Colin Ihrig Reviewed-By: Joyee Cheung --- 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 | 22 ++++++++++++++++++++++ 5 files changed, 29 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 878c0983..09b3f76d 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 b88ed359..8075f837 100644 --- a/test/fixtures/inspect-scenario.js +++ b/test/fixtures/inspect-scenario.js @@ -58,6 +58,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 f30085f9..2b870614 100644 --- a/test/plugin/inspect-test.js +++ b/test/plugin/inspect-test.js @@ -136,6 +136,28 @@ 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', + validator(t, sess, addresses, name, cb) { + const address = addresses[name]; + sess.send(`v8 inspect ${address}`); + + sess.linesUntil(/}>/, (err, lines) => { + if (err) return cb(err); + lines = lines.join('\n'); + + let codeMatch = lines.match(/code=(0x[0-9a-f]+):/i); + t.ok(codeMatch, 'hashmap.error.code should be "ERR_TEST"'); + + let errnoMatch = lines.match(/errno=/i); + t.ok(errnoMatch, 'hashmap.error.errno should be 1'); + + cb(null); + }); + } + }, // .array=0x000003df9cbe7919:, 'array': { re: /.array=(0x[0-9a-f]+):/,