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

PR-URL: nodejs#215
Refs: nodejs#143
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
  • Loading branch information
Matheus Marchini authored and hyj1991 committed Sep 17, 2018
1 parent cfdf83e commit dd76fec
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/llv8-constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
1 change: 1 addition & 0 deletions src/llv8-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 @@ -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/;
Expand Down
22 changes: 22 additions & 0 deletions test/plugin/inspect-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,28 @@ 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',
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]+):<String: "ERR_TEST">/i);
t.ok(codeMatch, 'hashmap.error.code should be "ERR_TEST"');

let errnoMatch = lines.match(/errno=<Smi: 1>/i);
t.ok(errnoMatch, 'hashmap.error.errno should be 1');

cb(null);
});
}
},
// .array=0x000003df9cbe7919:<Array: length=6>,
'array': {
re: /.array=(0x[0-9a-f]+):<Array: length=6>/,
Expand Down

0 comments on commit dd76fec

Please sign in to comment.