Skip to content

Commit

Permalink
src: add rudimentary Promise support
Browse files Browse the repository at this point in the history
This patch allows llnode to list Promise objects with findjsobjects,
findjsinstances and findrefs. We can investigate more fancy Promise
features in the future (such as listing handlers, Promise status, etc.).

For Node.js v10.x, since we don't have the JS_PROMISE type as postmortem
metadata, we assume JS_PROMISE is the next type after
JS_MESSAGE_OBJECT_TYPE. This is a safe assumption for Node.js v10.x,
v12.x has the JS_PROMISE type, and v8.x is not supported anymore.

```console
$ git log v10.0.0..v10.17.0 -L :InstanceType:deps/v8/src/objects.h \
    | grep -C2 "JS_PROMISE"
   JS_MAP_VALUE_ITERATOR_TYPE,
   JS_MESSAGE_OBJECT_TYPE,
   JS_PROMISE_TYPE,
   JS_REGEXP_TYPE,
   JS_REGEXP_STRING_ITERATOR_TYPE,
--
   JS_MAP_VALUE_ITERATOR_TYPE,
   JS_MESSAGE_OBJECT_TYPE,
   JS_PROMISE_TYPE,
   JS_REGEXP_TYPE,
+  JS_REGEXP_STRING_ITERATOR_TYPE,
```

PR-URL: #272
  • Loading branch information
mmarchini committed Mar 25, 2020
1 parent 83c810f commit 991c731
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/llv8-constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,13 @@ void Types::Load() {
kLastContextType = LoadConstant("LastContextType");

kJSErrorType = LoadConstant("type_JSError__JS_ERROR_TYPE");
kJSPromiseType = LoadConstant("type_JSPromise__JS_PROMISE_TYPE");
if (kJSPromiseType == -1) {
// NOTE(mmarchini): On Node.js v10.x, JS_PROMISE always comes after
// JS_MESSAGE_OBJECT_TYPE in the InstanceType enum.
kJSPromiseType =
LoadConstant("type_JSMessageObject__JS_MESSAGE_OBJECT_TYPE") + 1;
}
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 @@ -527,6 +527,7 @@ class Types : public Module {
int64_t kLastContextType;

int64_t kJSErrorType;
int64_t kJSPromiseType;
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 @@ -350,6 +350,7 @@ 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()->kJSPromiseType ||
type == v8->types()->kJSSpecialAPIObjectType;
}

Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/inspect-scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ function closure() {
c.hashmap['stringifiedError'] = new Error('test');
c.hashmap['stringifiedErrorStack'] = c.hashmap['stringifiedError'].stack;

c.hashmap['promise'] = new Promise(() => {});

c.hashmap[0] = null;
c.hashmap[4] = undefined;
c.hashmap[23] = /regexp/;
Expand Down
4 changes: 4 additions & 0 deletions test/plugin/inspect-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ const hashMapTests = {
});
}
},
'promise': {
re: /.promise=(0x[0-9a-f]+):<Object: Promise>/,
desc: '.promise Promise property'
},
// .array=0x000003df9cbe7919:<Array: length=6>,
'array': {
re: /.array=(0x[0-9a-f]+):<Array: length=6>/,
Expand Down

0 comments on commit 991c731

Please sign in to comment.