Skip to content

Commit

Permalink
deps: back-port 306c412c from v8 upstream
Browse files Browse the repository at this point in the history
The patch has been modified to maintain ABI compatibility.  The original
change removes the v8::FunctionCallbackInfo<T>::is_construct_call_ field
from deps/v8/include/v8.h.  The field is set directly by JIT-ted code so
the removal of those code paths has been backed out as well.

Original commit message:

    [api] Expose FunctionCallbackInfo::NewTarget

    This is needed by Blink to implement the Custom Elements spec.

    BUG=v8:4261
    LOG=y

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

Fixes: #9288
PR-URL: #9293
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
  • Loading branch information
bnoordhuis authored and MylesBorins committed Mar 9, 2017
1 parent fd1ffe4 commit e774de1
Show file tree
Hide file tree
Showing 23 changed files with 167 additions and 150 deletions.
9 changes: 8 additions & 1 deletion deps/v8/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -3177,12 +3177,13 @@ class FunctionCallbackInfo {
Local<Function> Callee() const);
V8_INLINE Local<Object> This() const;
V8_INLINE Local<Object> Holder() const;
V8_INLINE Local<Value> NewTarget() const;
V8_INLINE bool IsConstructCall() const;
V8_INLINE Local<Value> Data() const;
V8_INLINE Isolate* GetIsolate() const;
V8_INLINE ReturnValue<T> GetReturnValue() const;
// This shouldn't be public, but the arm compiler needs it.
static const int kArgsLength = 7;
static const int kArgsLength = 8;

protected:
friend class internal::FunctionCallbackArguments;
Expand All @@ -3194,6 +3195,7 @@ class FunctionCallbackInfo {
static const int kDataIndex = 4;
static const int kCalleeIndex = 5;
static const int kContextSaveIndex = 6;
static const int kNewTargetIndex = 7;

V8_INLINE FunctionCallbackInfo(internal::Object** implicit_args,
internal::Object** values,
Expand Down Expand Up @@ -7902,6 +7904,11 @@ Local<Object> FunctionCallbackInfo<T>::Holder() const {
&implicit_args_[kHolderIndex]));
}

template<typename T>
Local<Value> FunctionCallbackInfo<T>::NewTarget() const {
return Local<Value>(
reinterpret_cast<Value*>(&implicit_args_[kNewTargetIndex]));
}

template<typename T>
Local<Value> FunctionCallbackInfo<T>::Data() const {
Expand Down
9 changes: 6 additions & 3 deletions deps/v8/src/api-arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,22 @@ class FunctionCallbackArguments
static const int kIsolateIndex = T::kIsolateIndex;
static const int kCalleeIndex = T::kCalleeIndex;
static const int kContextSaveIndex = T::kContextSaveIndex;
static const int kNewTargetIndex = T::kNewTargetIndex;

FunctionCallbackArguments(internal::Isolate* isolate, internal::Object* data,
internal::HeapObject* callee,
internal::Object* holder, internal::Object** argv,
int argc, bool is_construct_call)
internal::Object* holder,
internal::HeapObject* new_target,
internal::Object** argv, int argc)
: Super(isolate),
argv_(argv),
argc_(argc),
is_construct_call_(is_construct_call) {
is_construct_call_(!new_target->IsUndefined()) {
Object** values = begin();
values[T::kDataIndex] = data;
values[T::kCalleeIndex] = callee;
values[T::kHolderIndex] = holder;
values[T::kNewTargetIndex] = new_target;
values[T::kContextSaveIndex] = isolate->heap()->the_hole_value();
values[T::kIsolateIndex] = reinterpret_cast<internal::Object*>(isolate);
// Here the hole is set as default value.
Expand Down
13 changes: 3 additions & 10 deletions deps/v8/src/arm/builtins-arm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -604,16 +604,9 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
// r0: number of arguments
// r1: constructor function
// r3: new target
if (is_api_function) {
__ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
Handle<Code> code =
masm->isolate()->builtins()->HandleApiCallConstruct();
__ Call(code, RelocInfo::CODE_TARGET);
} else {
ParameterCount actual(r0);
__ InvokeFunction(r1, r3, actual, CALL_FUNCTION,
CheckDebugStepCallWrapper());
}
ParameterCount actual(r0);
__ InvokeFunction(r1, r3, actual, CALL_FUNCTION,
CheckDebugStepCallWrapper());

// Store offset of return address for deoptimizer.
if (create_implicit_receiver && !is_api_function) {
Expand Down
6 changes: 5 additions & 1 deletion deps/v8/src/arm/code-stubs-arm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5423,7 +5423,11 @@ void CallApiCallbackStub::Generate(MacroAssembler* masm) {
STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
STATIC_ASSERT(FCA::kIsolateIndex == 1);
STATIC_ASSERT(FCA::kHolderIndex == 0);
STATIC_ASSERT(FCA::kArgsLength == 7);
STATIC_ASSERT(FCA::kNewTargetIndex == 7);
STATIC_ASSERT(FCA::kArgsLength == 8);

// new target
__ PushRoot(Heap::kUndefinedValueRootIndex);

// context save
__ push(context);
Expand Down
13 changes: 3 additions & 10 deletions deps/v8/src/arm64/builtins-arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -605,16 +605,9 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
// x0: number of arguments
// x1: constructor function
// x3: new target
if (is_api_function) {
__ Ldr(cp, FieldMemOperand(constructor, JSFunction::kContextOffset));
Handle<Code> code =
masm->isolate()->builtins()->HandleApiCallConstruct();
__ Call(code, RelocInfo::CODE_TARGET);
} else {
ParameterCount actual(argc);
__ InvokeFunction(constructor, new_target, actual, CALL_FUNCTION,
CheckDebugStepCallWrapper());
}
ParameterCount actual(argc);
__ InvokeFunction(constructor, new_target, actual, CALL_FUNCTION,
CheckDebugStepCallWrapper());

// Store offset of return address for deoptimizer.
if (create_implicit_receiver && !is_api_function) {
Expand Down
10 changes: 8 additions & 2 deletions deps/v8/src/arm64/code-stubs-arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5807,9 +5807,15 @@ void CallApiCallbackStub::Generate(MacroAssembler* masm) {
STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
STATIC_ASSERT(FCA::kIsolateIndex == 1);
STATIC_ASSERT(FCA::kHolderIndex == 0);
STATIC_ASSERT(FCA::kArgsLength == 7);
STATIC_ASSERT(FCA::kNewTargetIndex == 7);
STATIC_ASSERT(FCA::kArgsLength == 8);

// FunctionCallbackArguments: context, callee and call data.
// FunctionCallbackArguments

// new target
__ PushRoot(Heap::kUndefinedValueRootIndex);

// context, callee and call data.
__ Push(context, callee, call_data);

if (!is_lazy()) {
Expand Down
82 changes: 36 additions & 46 deletions deps/v8/src/builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,6 @@ Handle<S> BuiltinArguments<BuiltinExtraArguments::kTarget>::target() {
return Arguments::at<S>(Arguments::length() - 1);
}

template <>
int BuiltinArguments<BuiltinExtraArguments::kNewTarget>::length() const {
return Arguments::length() - 1;
}

template <>
Handle<HeapObject>
BuiltinArguments<BuiltinExtraArguments::kNewTarget>::new_target() {
return Arguments::at<HeapObject>(Arguments::length() - 1);
}

template <>
int BuiltinArguments<BuiltinExtraArguments::kTargetAndNewTarget>::length()
const {
Expand Down Expand Up @@ -4247,11 +4236,13 @@ BUILTIN(RestrictedStrictArgumentsPropertiesThrower) {

namespace {

template <bool is_construct>
MUST_USE_RESULT MaybeHandle<Object> HandleApiCallHelper(
Isolate* isolate, BuiltinArguments<BuiltinExtraArguments::kTarget> args) {
Isolate* isolate,
BuiltinArguments<BuiltinExtraArguments::kTargetAndNewTarget> args) {
HandleScope scope(isolate);
Handle<HeapObject> function = args.target<HeapObject>();
Handle<HeapObject> new_target = args.new_target();
bool is_construct = !new_target->IsUndefined();
Handle<JSReceiver> receiver;

DCHECK(function->IsFunctionTemplateInfo() ||
Expand Down Expand Up @@ -4311,13 +4302,9 @@ MUST_USE_RESULT MaybeHandle<Object> HandleApiCallHelper(
LOG(isolate, ApiObjectAccess("call", JSObject::cast(*args.receiver())));
DCHECK(raw_holder->IsJSObject());

FunctionCallbackArguments custom(isolate,
data_obj,
*function,
raw_holder,
&args[0] - 1,
args.length() - 1,
is_construct);
FunctionCallbackArguments custom(isolate, data_obj, *function, raw_holder,
*new_target, &args[0] - 1,
args.length() - 1);

Handle<Object> result = custom.Call(callback);
if (result.is_null()) result = isolate->factory()->undefined_value();
Expand All @@ -4338,19 +4325,11 @@ BUILTIN(HandleApiCall) {
HandleScope scope(isolate);
Handle<Object> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
HandleApiCallHelper<false>(isolate, args));
HandleApiCallHelper(isolate, args));
return *result;
}


BUILTIN(HandleApiCallConstruct) {
HandleScope scope(isolate);
Handle<Object> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
HandleApiCallHelper<true>(isolate, args));
return *result;
}

Handle<Code> Builtins::CallFunction(ConvertReceiverMode mode,
TailCallMode tail_call_mode) {
switch (tail_call_mode) {
Expand Down Expand Up @@ -4432,11 +4411,12 @@ Handle<Code> Builtins::InterpreterPushArgsAndCall(TailCallMode tail_call_mode) {
namespace {

class RelocatableArguments
: public BuiltinArguments<BuiltinExtraArguments::kTarget>,
: public BuiltinArguments<BuiltinExtraArguments::kTargetAndNewTarget>,
public Relocatable {
public:
RelocatableArguments(Isolate* isolate, int length, Object** arguments)
: BuiltinArguments<BuiltinExtraArguments::kTarget>(length, arguments),
: BuiltinArguments<BuiltinExtraArguments::kTargetAndNewTarget>(length,
arguments),
Relocatable(isolate) {}

virtual inline void IterateInstance(ObjectVisitor* v) {
Expand Down Expand Up @@ -4468,24 +4448,26 @@ MaybeHandle<Object> Builtins::InvokeApiFunction(Handle<HeapObject> function,
}
}
}
// Construct BuiltinArguments object: function, arguments reversed, receiver.
// Construct BuiltinArguments object:
// new target, function, arguments reversed, receiver.
const int kBufferSize = 32;
Object* small_argv[kBufferSize];
Object** argv;
if (argc + 2 <= kBufferSize) {
if (argc + 3 <= kBufferSize) {
argv = small_argv;
} else {
argv = new Object* [argc + 2];
argv = new Object*[argc + 3];
}
argv[argc + 1] = *receiver;
argv[argc + 2] = *receiver;
for (int i = 0; i < argc; ++i) {
argv[argc - i] = *args[i];
argv[argc - i + 1] = *args[i];
}
argv[0] = *function;
argv[1] = *function;
argv[0] = isolate->heap()->undefined_value(); // new target
MaybeHandle<Object> result;
{
RelocatableArguments arguments(isolate, argc + 2, &argv[argc + 1]);
result = HandleApiCallHelper<false>(isolate, arguments);
RelocatableArguments arguments(isolate, argc + 3, &argv[argc] + 2);
result = HandleApiCallHelper(isolate, arguments);
}
if (argv != small_argv) {
delete[] argv;
Expand All @@ -4505,6 +4487,18 @@ MUST_USE_RESULT static Object* HandleApiCallAsFunctionOrConstructor(
// Get the object called.
JSObject* obj = JSObject::cast(*receiver);

// Set the new target.
HeapObject* new_target;
if (is_construct_call) {
// TODO(adamk): This should be passed through in args instead of
// being patched in here. We need to set a non-undefined value
// for v8::FunctionCallbackInfo::IsConstructCall() to get the
// right answer.
new_target = obj;
} else {
new_target = isolate->heap()->undefined_value();
}

// Get the invocation callback from the function descriptor that was
// used to create the called object.
DCHECK(obj->map()->is_callable());
Expand All @@ -4527,13 +4521,9 @@ MUST_USE_RESULT static Object* HandleApiCallAsFunctionOrConstructor(
HandleScope scope(isolate);
LOG(isolate, ApiObjectAccess("call non-function", obj));

FunctionCallbackArguments custom(isolate,
call_data->data(),
constructor,
obj,
&args[0] - 1,
args.length() - 1,
is_construct_call);
FunctionCallbackArguments custom(isolate, call_data->data(), constructor,
obj, new_target, &args[0] - 1,
args.length() - 1);
Handle<Object> result_handle = custom.Call(callback);
if (result_handle.is_null()) {
result = isolate->heap()->undefined_value();
Expand Down
3 changes: 1 addition & 2 deletions deps/v8/src/builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ inline bool operator&(BuiltinExtraArguments lhs, BuiltinExtraArguments rhs) {
V(SymbolConstructor, kNone) \
V(SymbolConstructor_ConstructStub, kTarget) \
\
V(HandleApiCall, kTarget) \
V(HandleApiCallConstruct, kTarget) \
V(HandleApiCall, kTargetAndNewTarget) \
V(HandleApiCallAsFunction, kNone) \
V(HandleApiCallAsConstructor, kNone) \
\
Expand Down
13 changes: 3 additions & 10 deletions deps/v8/src/ia32/builtins-ia32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,9 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
__ j(greater_equal, &loop);

// Call the function.
if (is_api_function) {
__ mov(esi, FieldOperand(edi, JSFunction::kContextOffset));
Handle<Code> code =
masm->isolate()->builtins()->HandleApiCallConstruct();
__ call(code, RelocInfo::CODE_TARGET);
} else {
ParameterCount actual(eax);
__ InvokeFunction(edi, edx, actual, CALL_FUNCTION,
CheckDebugStepCallWrapper());
}
ParameterCount actual(eax);
__ InvokeFunction(edi, edx, actual, CALL_FUNCTION,
CheckDebugStepCallWrapper());

// Store offset of return address for deoptimizer.
if (create_implicit_receiver && !is_api_function) {
Expand Down
7 changes: 6 additions & 1 deletion deps/v8/src/ia32/code-stubs-ia32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5686,9 +5686,14 @@ void CallApiCallbackStub::Generate(MacroAssembler* masm) {
STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
STATIC_ASSERT(FCA::kIsolateIndex == 1);
STATIC_ASSERT(FCA::kHolderIndex == 0);
STATIC_ASSERT(FCA::kArgsLength == 7);
STATIC_ASSERT(FCA::kNewTargetIndex == 7);
STATIC_ASSERT(FCA::kArgsLength == 8);

__ pop(return_address);

// new target
__ PushRoot(Heap::kUndefinedValueRootIndex);

// context save.
__ push(context);

Expand Down
13 changes: 3 additions & 10 deletions deps/v8/src/mips/builtins-mips.cc
Original file line number Diff line number Diff line change
Expand Up @@ -603,16 +603,9 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
// a0: number of arguments
// a1: constructor function
// a3: new target
if (is_api_function) {
__ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
Handle<Code> code =
masm->isolate()->builtins()->HandleApiCallConstruct();
__ Call(code, RelocInfo::CODE_TARGET);
} else {
ParameterCount actual(a0);
__ InvokeFunction(a1, a3, actual, CALL_FUNCTION,
CheckDebugStepCallWrapper());
}
ParameterCount actual(a0);
__ InvokeFunction(a1, a3, actual, CALL_FUNCTION,
CheckDebugStepCallWrapper());

// Store offset of return address for deoptimizer.
if (create_implicit_receiver && !is_api_function) {
Expand Down
6 changes: 5 additions & 1 deletion deps/v8/src/mips/code-stubs-mips.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5608,7 +5608,11 @@ void CallApiCallbackStub::Generate(MacroAssembler* masm) {
STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
STATIC_ASSERT(FCA::kIsolateIndex == 1);
STATIC_ASSERT(FCA::kHolderIndex == 0);
STATIC_ASSERT(FCA::kArgsLength == 7);
STATIC_ASSERT(FCA::kNewTargetIndex == 7);
STATIC_ASSERT(FCA::kArgsLength == 8);

// new target
__ PushRoot(Heap::kUndefinedValueRootIndex);

// Save context, callee and call data.
__ Push(context, callee, call_data);
Expand Down
13 changes: 3 additions & 10 deletions deps/v8/src/mips64/builtins-mips64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -592,16 +592,9 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
// a0: number of arguments
// a1: constructor function
// a3: new target
if (is_api_function) {
__ ld(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
Handle<Code> code =
masm->isolate()->builtins()->HandleApiCallConstruct();
__ Call(code, RelocInfo::CODE_TARGET);
} else {
ParameterCount actual(a0);
__ InvokeFunction(a1, a3, actual, CALL_FUNCTION,
CheckDebugStepCallWrapper());
}
ParameterCount actual(a0);
__ InvokeFunction(a1, a3, actual, CALL_FUNCTION,
CheckDebugStepCallWrapper());

// Store offset of return address for deoptimizer.
if (create_implicit_receiver && !is_api_function) {
Expand Down
Loading

0 comments on commit e774de1

Please sign in to comment.