Skip to content

Commit dd76fec

Browse files
Matheus Marchinihyj1991
Matheus Marchini
authored and
hyj1991
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: nodejs#143 PR-URL: nodejs#215 Refs: nodejs#143 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent cfdf83e commit dd76fec

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

src/llv8-constants.cc

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ function closure() {
5858
);
5959
c.hashmap['buffer'] = Buffer.from([0xff, 0xf0, 0x80, 0x0f, 0x01, 0x00]);
6060

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

test/plugin/inspect-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,28 @@ const hashMapTests = {
136136
re: /.sliced-externalized-string=(0x[0-9a-f]+):<String: "\(external\)">/,
137137
desc: '.sliced-externalized-string Sliced ExternalString property'
138138
},
139+
// .error=0x0000392d5d661119:<Object: Error>
140+
'error': {
141+
re: /.error=(0x[0-9a-f]+):<Object: Error>/,
142+
desc: '.error Error property',
143+
validator(t, sess, addresses, name, cb) {
144+
const address = addresses[name];
145+
sess.send(`v8 inspect ${address}`);
146+
147+
sess.linesUntil(/}>/, (err, lines) => {
148+
if (err) return cb(err);
149+
lines = lines.join('\n');
150+
151+
let codeMatch = lines.match(/code=(0x[0-9a-f]+):<String: "ERR_TEST">/i);
152+
t.ok(codeMatch, 'hashmap.error.code should be "ERR_TEST"');
153+
154+
let errnoMatch = lines.match(/errno=<Smi: 1>/i);
155+
t.ok(errnoMatch, 'hashmap.error.errno should be 1');
156+
157+
cb(null);
158+
});
159+
}
160+
},
139161
// .array=0x000003df9cbe7919:<Array: length=6>,
140162
'array': {
141163
re: /.array=(0x[0-9a-f]+):<Array: length=6>/,

0 commit comments

Comments
 (0)