From e6395cc07ae54f81699e369d292da29ecf113a16 Mon Sep 17 00:00:00 2001 From: Matt Loring Date: Tue, 23 May 2017 12:17:17 -0700 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/13175 Reviewed-By: Ali Ijaz Sheikh Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- deps/v8/BUILD.gn | 7 +++++++ deps/v8/gypfiles/features.gypi | 5 +++++ deps/v8/include/v8-version.h | 2 +- deps/v8/include/v8.h | 6 ++++++ deps/v8/src/bootstrapper.cc | 6 +++--- deps/v8/src/builtins/builtins-promise.cc | 8 ++++++++ deps/v8/src/objects.h | 2 ++ 7 files changed, 32 insertions(+), 4 deletions(-) diff --git a/deps/v8/BUILD.gn b/deps/v8/BUILD.gn index 8895103222b..2a77a0ded02 100644 --- a/deps/v8/BUILD.gn +++ b/deps/v8/BUILD.gn @@ -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" ] } diff --git a/deps/v8/gypfiles/features.gypi b/deps/v8/gypfiles/features.gypi index 0c4873c3a5f..bd5cd7cd108 100644 --- a/deps/v8/gypfiles/features.gypi +++ b/deps/v8/gypfiles/features.gypi @@ -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',], }], diff --git a/deps/v8/include/v8-version.h b/deps/v8/include/v8-version.h index f0866a2d9b3..70e1a84d09e 100644 --- a/deps/v8/include/v8-version.h +++ b/deps/v8/include/v8-version.h @@ -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.) diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h index e38f657b48f..9ae8e1b9487 100644 --- a/deps/v8/include/v8.h +++ b/deps/v8/include/v8.h @@ -3741,6 +3741,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). @@ -3822,6 +3826,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); diff --git a/deps/v8/src/bootstrapper.cc b/deps/v8/src/bootstrapper.cc index 8f9f92a08c6..60e989ae17a 100644 --- a/deps/v8/src/bootstrapper.cc +++ b/deps/v8/src/bootstrapper.cc @@ -1945,9 +1945,9 @@ void Genesis::InitializeGlobal(Handle global_object, Handle prototype = factory->NewJSObject(isolate->object_function(), TENURED); - Handle promise_fun = - InstallFunction(global, "Promise", JS_PROMISE_TYPE, JSPromise::kSize, - prototype, Builtins::kPromiseConstructor); + Handle promise_fun = InstallFunction( + global, "Promise", JS_PROMISE_TYPE, JSPromise::kSizeWithEmbedderFields, + prototype, Builtins::kPromiseConstructor); InstallWithIntrinsicDefaultProto(isolate, promise_fun, Context::PROMISE_FUNCTION_INDEX); diff --git a/deps/v8/src/builtins/builtins-promise.cc b/deps/v8/src/builtins/builtins-promise.cc index 0d0238d267e..6d9fed83a96 100644 --- a/deps/v8/src/builtins/builtins-promise.cc +++ b/deps/v8/src/builtins/builtins-promise.cc @@ -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); diff --git a/deps/v8/src/objects.h b/deps/v8/src/objects.h index ca4c3513170..3b4ff9bb751 100644 --- a/deps/v8/src/objects.h +++ b/deps/v8/src/objects.h @@ -8443,6 +8443,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;