Skip to content

Commit 991c731

Browse files
committed
src: add rudimentary Promise support
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
1 parent 83c810f commit 991c731

File tree

5 files changed

+15
-0
lines changed

5 files changed

+15
-0
lines changed

src/llv8-constants.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,13 @@ void Types::Load() {
580580
kLastContextType = LoadConstant("LastContextType");
581581

582582
kJSErrorType = LoadConstant("type_JSError__JS_ERROR_TYPE");
583+
kJSPromiseType = LoadConstant("type_JSPromise__JS_PROMISE_TYPE");
584+
if (kJSPromiseType == -1) {
585+
// NOTE(mmarchini): On Node.js v10.x, JS_PROMISE always comes after
586+
// JS_MESSAGE_OBJECT_TYPE in the InstanceType enum.
587+
kJSPromiseType =
588+
LoadConstant("type_JSMessageObject__JS_MESSAGE_OBJECT_TYPE") + 1;
589+
}
583590
kHeapNumberType = LoadConstant("type_HeapNumber__HEAP_NUMBER_TYPE");
584591
kMapType = LoadConstant("type_Map__MAP_TYPE");
585592
kGlobalObjectType =

src/llv8-constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ class Types : public Module {
527527
int64_t kLastContextType;
528528

529529
int64_t kJSErrorType;
530+
int64_t kJSPromiseType;
530531
int64_t kHeapNumberType;
531532
int64_t kMapType;
532533
int64_t kGlobalObjectType;

src/llv8-inl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ inline bool JSObject::IsObjectType(LLV8* v8, int64_t type) {
350350
return type == v8->types()->kJSObjectType ||
351351
type == v8->types()->kJSAPIObjectType ||
352352
type == v8->types()->kJSErrorType ||
353+
type == v8->types()->kJSPromiseType ||
353354
type == v8->types()->kJSSpecialAPIObjectType;
354355
}
355356

test/fixtures/inspect-scenario.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ function closure() {
6767
c.hashmap['stringifiedError'] = new Error('test');
6868
c.hashmap['stringifiedErrorStack'] = c.hashmap['stringifiedError'].stack;
6969

70+
c.hashmap['promise'] = new Promise(() => {});
71+
7072
c.hashmap[0] = null;
7173
c.hashmap[4] = undefined;
7274
c.hashmap[23] = /regexp/;

test/plugin/inspect-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ const hashMapTests = {
185185
});
186186
}
187187
},
188+
'promise': {
189+
re: /.promise=(0x[0-9a-f]+):<Object: Promise>/,
190+
desc: '.promise Promise property'
191+
},
188192
// .array=0x000003df9cbe7919:<Array: length=6>,
189193
'array': {
190194
re: /.array=(0x[0-9a-f]+):<Array: length=6>/,

0 commit comments

Comments
 (0)