Skip to content

Commit

Permalink
deps: cherry-pick 6803eef from V8 upstream
Browse files Browse the repository at this point in the history
Original commit message:
  Allow embedder to set promise internal field count

  Asynchronous context tracking mechanisms in Node.js need to store some
  state on all promise objects. This change will allow embedders to
  configure the number of internal fields on promises as is already done
  for ArrayBuffers.

  BUG=v8:6435

  Review-Url: https://codereview.chromium.org/2889863002
  Cr-Commit-Position: refs/heads/master@{#45496}

PR-URL: #13175
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
Matt Loring authored and jasnell committed May 28, 2017
1 parent 3becb02 commit 9302f51
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 4 deletions.
7 changes: 7 additions & 0 deletions deps/v8/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ declare_args() {
# Sets -dENABLE_DISASSEMBLER.
v8_enable_disassembler = ""

# Sets the number of internal fields on promise objects.
v8_promise_internal_field_count = 0

# Sets -dENABLE_GDB_JIT_INTERFACE.
v8_enable_gdbjit = ""

Expand Down Expand Up @@ -197,6 +200,10 @@ config("features") {
if (v8_enable_disassembler) {
defines += [ "ENABLE_DISASSEMBLER" ]
}
if (v8_promise_internal_field_count != 0) {
defines +=
[ "V8_PROMISE_INTERNAL_FIELD_COUNT=${v8_promise_internal_field_count}" ]
}
if (v8_enable_gdbjit) {
defines += [ "ENABLE_GDB_JIT_INTERFACE" ]
}
Expand Down
5 changes: 5 additions & 0 deletions deps/v8/gypfiles/features.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
'variables': {
'v8_enable_disassembler%': 0,

'v8_promise_internal_field_count%': 0,

'v8_enable_gdbjit%': 0,

'v8_enable_verify_csa%': 0,
Expand Down Expand Up @@ -77,6 +79,9 @@
['v8_enable_disassembler==1', {
'defines': ['ENABLE_DISASSEMBLER',],
}],
['v8_promise_internal_field_count!=0', {
'defines': ['V8_PROMISE_INTERNAL_FIELD_COUNT','v8_promise_internal_field_count'],
}],
['v8_enable_gdbjit==1', {
'defines': ['ENABLE_GDB_JIT_INTERFACE',],
}],
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/include/v8-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define V8_MAJOR_VERSION 5
#define V8_MINOR_VERSION 8
#define V8_BUILD_NUMBER 283
#define V8_PATCH_LEVEL 40
#define V8_PATCH_LEVEL 41

// Use 1 for candidates and 0 otherwise.
// (Boolean macro values are not supported by all preprocessors.)
Expand Down
6 changes: 6 additions & 0 deletions deps/v8/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -3743,6 +3743,10 @@ class V8_EXPORT Function : public Object {
static void CheckCast(Value* obj);
};

#ifndef V8_PROMISE_INTERNAL_FIELD_COUNT
// The number of required internal fields can be defined by embedder.
#define V8_PROMISE_INTERNAL_FIELD_COUNT 0
#endif

/**
* An instance of the built-in Promise constructor (ES6 draft).
Expand Down Expand Up @@ -3824,6 +3828,8 @@ class V8_EXPORT Promise : public Object {

V8_INLINE static Promise* Cast(Value* obj);

static const int kEmbedderFieldCount = V8_PROMISE_INTERNAL_FIELD_COUNT;

private:
Promise();
static void CheckCast(Value* obj);
Expand Down
6 changes: 3 additions & 3 deletions deps/v8/src/bootstrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1945,9 +1945,9 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,

Handle<JSObject> prototype =
factory->NewJSObject(isolate->object_function(), TENURED);
Handle<JSFunction> promise_fun =
InstallFunction(global, "Promise", JS_PROMISE_TYPE, JSPromise::kSize,
prototype, Builtins::kPromiseConstructor);
Handle<JSFunction> promise_fun = InstallFunction(
global, "Promise", JS_PROMISE_TYPE, JSPromise::kSizeWithEmbedderFields,
prototype, Builtins::kPromiseConstructor);
InstallWithIntrinsicDefaultProto(isolate, promise_fun,
Context::PROMISE_FUNCTION_INDEX);

Expand Down
8 changes: 8 additions & 0 deletions deps/v8/src/builtins/builtins-promise.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ void PromiseBuiltinsAssembler::PromiseInit(Node* promise) {
StoreObjectField(promise, JSPromise::kStatusOffset,
SmiConstant(v8::Promise::kPending));
StoreObjectField(promise, JSPromise::kFlagsOffset, SmiConstant(0));
for (int i = 0; i < v8::Promise::kEmbedderFieldCount; i++) {
int offset = JSPromise::kSize + i * kPointerSize;
StoreObjectFieldNoWriteBarrier(promise, offset, SmiConstant(Smi::kZero));
}
}

Node* PromiseBuiltinsAssembler::AllocateAndInitJSPromise(Node* context) {
Expand Down Expand Up @@ -62,6 +66,10 @@ Node* PromiseBuiltinsAssembler::AllocateAndSetJSPromise(Node* context,
StoreObjectFieldNoWriteBarrier(instance, JSPromise::kResultOffset, result);
StoreObjectFieldNoWriteBarrier(instance, JSPromise::kFlagsOffset,
SmiConstant(0));
for (int i = 0; i < v8::Promise::kEmbedderFieldCount; i++) {
int offset = JSPromise::kSize + i * kPointerSize;
StoreObjectFieldNoWriteBarrier(instance, offset, SmiConstant(Smi::kZero));
}

Label out(this);
GotoIfNot(IsPromiseHookEnabledOrDebugIsActive(), &out);
Expand Down
2 changes: 2 additions & 0 deletions deps/v8/src/objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -8447,6 +8447,8 @@ class JSPromise : public JSObject {
kFulfillReactionsOffset + kPointerSize;
static const int kFlagsOffset = kRejectReactionsOffset + kPointerSize;
static const int kSize = kFlagsOffset + kPointerSize;
static const int kSizeWithEmbedderFields =
kSize + v8::Promise::kEmbedderFieldCount * kPointerSize;

// Flags layout.
static const int kHasHandlerBit = 0;
Expand Down

0 comments on commit 9302f51

Please sign in to comment.