Skip to content

Commit

Permalink
src: fix JSError inspection
Browse files Browse the repository at this point in the history
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: nodejs#143
  • Loading branch information
Matheus Marchini committed Aug 8, 2018
1 parent 5b6a6b5 commit 901e3cf
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/llv8-constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ void Types::Load() {
kFirstJSObjectType =
LoadConstant("type_JSGlobalObject__JS_GLOBAL_OBJECT_TYPE");

kJSErrorType = LoadConstant("type_JSError__JS_ERROR_TYPE");
kHeapNumberType = LoadConstant("type_HeapNumber__HEAP_NUMBER_TYPE");
kMapType = LoadConstant("type_Map__MAP_TYPE");
kGlobalObjectType =
Expand Down
1 change: 1 addition & 0 deletions src/llv8-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ class Types : public Module {
int64_t kFirstNonstringType;
int64_t kFirstJSObjectType;

int64_t kJSErrorType;
int64_t kHeapNumberType;
int64_t kMapType;
int64_t kGlobalObjectType;
Expand Down
1 change: 1 addition & 0 deletions src/llv8-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/inspect-scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/;
Expand Down
7 changes: 6 additions & 1 deletion test/plugin/inspect-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const hashMapTests = {
const arrowSource = 'source:\n' +
'function c.hashmap.(anonymous function)(a,b)=>{a+b}\n' +
'>';

t.ok(lines.includes(arrowSource),
'hashmap[25] should have the correct function source');
cb(null);
Expand Down Expand Up @@ -133,6 +133,11 @@ const hashMapTests = {
re: /.sliced-externalized-string=(0x[0-9a-f]+):<String: "\(external\)">/,
desc: '.sliced-externalized-string Sliced ExternalString property'
},
// .error=0x0000392d5d661119:<Object: Error>
'error': {
re: /.error=(0x[0-9a-f]+):<Object: Error>/,
desc: '.error Error property'
},
// .array=0x000003df9cbe7919:<Array: length=6>,
'array': {
re: /.array=(0x[0-9a-f]+):<Array: length=6>/,
Expand Down

0 comments on commit 901e3cf

Please sign in to comment.