Skip to content

Commit 82a3383

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, ```
1 parent ecb8d0e commit 82a3383

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/llv8-constants.cc

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

520520
kJSErrorType = LoadConstant("type_JSError__JS_ERROR_TYPE");
521+
kJSPromiseType = LoadConstant("type_JSPromise__JS_PROMISE_TYPE");
522+
if (kJSPromiseType == -1) {
523+
// NOTE(mmarchini): On Node.js v10.x, JS_PROMISE always comes after
524+
// JS_MESSAGE_OBJECT_TYPE in the InstanceType enum.
525+
kJSPromiseType =
526+
LoadConstant("type_JSMessageObject__JS_MESSAGE_OBJECT_TYPE") + 1;
527+
}
521528
kHeapNumberType = LoadConstant("type_HeapNumber__HEAP_NUMBER_TYPE");
522529
kMapType = LoadConstant("type_Map__MAP_TYPE");
523530
kGlobalObjectType =

src/llv8-constants.h

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

509509
int64_t kJSErrorType;
510+
int64_t kJSPromiseType;
510511
int64_t kHeapNumberType;
511512
int64_t kMapType;
512513
int64_t kGlobalObjectType;

src/llv8-inl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ inline bool JSObject::IsObjectType(LLV8* v8, int64_t type) {
314314
return type == v8->types()->kJSObjectType ||
315315
type == v8->types()->kJSAPIObjectType ||
316316
type == v8->types()->kJSErrorType ||
317+
type == v8->types()->kJSPromiseType ||
317318
type == v8->types()->kJSSpecialAPIObjectType;
318319
}
319320

0 commit comments

Comments
 (0)