Permalink
Browse files

deps: cherry-pick 6803eef from V8 upstream

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 <ofrobots@google.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
matthewloring authored and jasnell committed May 23, 2017
1 parent 3becb02 commit 9302f512f8d1b63aacc91427f77b11f97a16f958
View
@@ -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 = ""
@@ -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" ]
}
@@ -31,6 +31,8 @@
'variables': {
'v8_enable_disassembler%': 0,
'v8_promise_internal_field_count%': 0,
'v8_enable_gdbjit%': 0,
'v8_enable_verify_csa%': 0,
@@ -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',],
}],
@@ -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.)
View
@@ -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).
@@ -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);
@@ -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);
@@ -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) {
@@ -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);
View
@@ -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;

0 comments on commit 9302f51

Please sign in to comment.