Skip to content

Commit 21cf534

Browse files
author
Matheus Marchini
committed
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: #143
1 parent baf4cae commit 21cf534

File tree

5 files changed

+13
-1
lines changed

5 files changed

+13
-1
lines changed

src/llv8-constants.cc

+1
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ void Types::Load() {
486486
kFirstJSObjectType =
487487
LoadConstant("type_JSGlobalObject__JS_GLOBAL_OBJECT_TYPE");
488488

489+
kJSErrorType = LoadConstant("type_JSError__JS_ERROR_TYPE");
489490
kHeapNumberType = LoadConstant("type_HeapNumber__HEAP_NUMBER_TYPE");
490491
kMapType = LoadConstant("type_Map__MAP_TYPE");
491492
kGlobalObjectType =

src/llv8-constants.h

+1
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ class Types : public Module {
465465
int64_t kFirstNonstringType;
466466
int64_t kFirstJSObjectType;
467467

468+
int64_t kJSErrorType;
468469
int64_t kHeapNumberType;
469470
int64_t kMapType;
470471
int64_t kGlobalObjectType;

src/llv8-inl.h

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ ACCESSOR(JSObject, Elements, js_object()->kElementsOffset, HeapObject)
211211
inline bool JSObject::IsObjectType(LLV8* v8, int64_t type) {
212212
return type == v8->types()->kJSObjectType ||
213213
type == v8->types()->kJSAPIObjectType ||
214+
type == v8->types()->kJSErrorType ||
214215
type == v8->types()->kJSSpecialAPIObjectType;
215216
}
216217

test/fixtures/inspect-scenario.js

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ function closure() {
5757
);
5858
c.hashmap['buffer'] = Buffer.from([0xff, 0xf0, 0x80, 0x0f, 0x01, 0x00]);
5959

60+
c.hashmap['error'] = new Error('test');
61+
c.hashmap['error'].code = 'ERR_TEST';
62+
c.hashmap['error'].errno = 1;
63+
6064
c.hashmap[0] = null;
6165
c.hashmap[4] = undefined;
6266
c.hashmap[23] = /regexp/;

test/plugin/inspect-test.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const hashMapTests = {
5151
const arrowSource = 'source:\n' +
5252
'function c.hashmap.(anonymous function)(a,b)=>{a+b}\n' +
5353
'>';
54-
54+
5555
t.ok(lines.includes(arrowSource),
5656
'hashmap[25] should have the correct function source');
5757
cb(null);
@@ -133,6 +133,11 @@ const hashMapTests = {
133133
re: /.sliced-externalized-string=(0x[0-9a-f]+):<String: "\(external\)">/,
134134
desc: '.sliced-externalized-string Sliced ExternalString property'
135135
},
136+
// .error=0x0000392d5d661119:<Object: Error>
137+
'error': {
138+
re: /.error=(0x[0-9a-f]+):<Object: Error>/,
139+
desc: '.error Error property'
140+
},
136141
// .array=0x000003df9cbe7919:<Array: length=6>,
137142
'array': {
138143
re: /.array=(0x[0-9a-f]+):<Array: length=6>/,

0 commit comments

Comments
 (0)