Skip to content

Commit

Permalink
Merged: Allow embedder to set promise internal field count
Browse files Browse the repository at this point in the history
Revision: 6803eef

BUG=v8:6435
LOG=N
NOTRY=true
NOPRESUBMIT=true
NOTREECHECKS=true
[email protected], [email protected]

Change-Id: I36d1c19324f51dde6356a8db2383036cc5f77c24
Reviewed-on: https://chromium-review.googlesource.com/523006
Reviewed-by: Adam Klein <[email protected]>
Commit-Queue: Ali Ijaz Sheikh <[email protected]>
Cr-Commit-Position: refs/branch-heads/5.9@{crosswalk-project#67}
Cr-Branched-From: fe9bb7e-refs/heads/5.9.211@{crosswalk-project#1}
Cr-Branched-From: 70ad237-refs/heads/master@{#44591}
  • Loading branch information
ofrobots authored and Commit Bot committed Jun 6, 2017
1 parent 630ab7d commit b17bdfe
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 3 deletions.
7 changes: 7 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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 @@ -218,6 +221,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_future) {
defines += [ "V8_ENABLE_FUTURE" ]
}
Expand Down
5 changes: 5 additions & 0 deletions 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
6 changes: 6 additions & 0 deletions include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -3823,6 +3823,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 @@ -3904,6 +3908,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 src/bootstrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2088,9 +2088,9 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
{ // -- P r o m i s e
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 src/builtins/builtins-promise-gen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ void PromiseBuiltinsAssembler::PromiseInit(Node* promise) {
SmiConstant(v8::Promise::kPending));
StoreObjectFieldNoWriteBarrier(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
3 changes: 3 additions & 0 deletions src/factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,9 @@ Handle<JSPromise> Factory::NewJSPromise() {
Handle<JSPromise> promise = Handle<JSPromise>::cast(promise_obj);
promise->set_status(v8::Promise::kPending);
promise->set_flags(0);
for (int i = 0; i < v8::Promise::kEmbedderFieldCount; i++) {
promise->SetEmbedderField(i, Smi::kZero);
}

isolate()->RunPromiseHook(PromiseHookType::kInit, promise, undefined_value());
return promise;
Expand Down
2 changes: 2 additions & 0 deletions src/objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -7339,6 +7339,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 b17bdfe

Please sign in to comment.