Skip to content

Commit 816c46c

Browse files
Matheus Marchinimmarchini
Matheus Marchini
authored andcommitted
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 PR-URL: #215 Refs: #143 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent fe238a0 commit 816c46c

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

src/llv8-constants.cc

+1
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ void Types::Load() {
490490
kFirstContextType = LoadConstant("FirstContextType");
491491
kLastContextType = LoadConstant("LastContextType");
492492

493+
kJSErrorType = LoadConstant("type_JSError__JS_ERROR_TYPE");
493494
kHeapNumberType = LoadConstant("type_HeapNumber__HEAP_NUMBER_TYPE");
494495
kMapType = LoadConstant("type_Map__MAP_TYPE");
495496
kGlobalObjectType =

src/llv8-constants.h

+1
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ class Types : public Module {
478478
int64_t kFirstContextType;
479479
int64_t kLastContextType;
480480

481+
int64_t kJSErrorType;
481482
int64_t kHeapNumberType;
482483
int64_t kMapType;
483484
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

+22
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,28 @@ 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+
validator(t, sess, addresses, name, cb) {
141+
const address = addresses[name];
142+
sess.send(`v8 inspect ${address}`);
143+
144+
sess.linesUntil(/}>/, (err, lines) => {
145+
if (err) return cb(err);
146+
lines = lines.join('\n');
147+
148+
let codeMatch = lines.match(/code=(0x[0-9a-f]+):<String: "ERR_TEST">/i);
149+
t.ok(codeMatch, 'hashmap.error.code should be "ERR_TEST"');
150+
151+
let errnoMatch = lines.match(/errno=<Smi: 1>/i);
152+
t.ok(errnoMatch, 'hashmap.error.errno should be 1');
153+
154+
cb(null);
155+
});
156+
}
157+
},
136158
// .array=0x000003df9cbe7919:<Array: length=6>,
137159
'array': {
138160
re: /.array=(0x[0-9a-f]+):<Array: length=6>/,

0 commit comments

Comments
 (0)