Commit 5d14e4bc authored by dcarney's avatar dcarney Committed by Commit bot

Revert of Call directly to c callbacks in Invoke instead of transitioning to...

Revert of Call directly to c callbacks in Invoke instead of transitioning to js and back out. (patchset #9 id:150001 of https://codereview.chromium.org/864273002/)

Reason for revert:
threading4 flakiness

Original issue's description:
> Call directly to c callbacks in Invoke instead of transitioning to js and back out.
>
> BUG=
>
> Committed: https://crrev.com/ce457e2b596c3ccf5bf454eeed0969f3f3efd174
> Cr-Commit-Position: refs/heads/master@{#26231}

TBR=verwaest@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=

Review URL: https://codereview.chromium.org/873583003

Cr-Commit-Position: refs/heads/master@{#26236}
parent 03fbb053
...@@ -1062,8 +1062,11 @@ static inline Object* TypeCheck(Heap* heap, Object* recv, ...@@ -1062,8 +1062,11 @@ static inline Object* TypeCheck(Heap* heap, Object* recv,
template <bool is_construct> template <bool is_construct>
MUST_USE_RESULT static MaybeHandle<Object> HandleApiCallHelper( MUST_USE_RESULT static Object* HandleApiCallHelper(
Isolate* isolate, BuiltinArguments<NEEDS_CALLED_FUNCTION> args) { BuiltinArguments<NEEDS_CALLED_FUNCTION> args, Isolate* isolate) {
DCHECK(is_construct == CalledAsConstructor(isolate));
Heap* heap = isolate->heap();
HandleScope scope(isolate); HandleScope scope(isolate);
Handle<JSFunction> function = args.called_function(); Handle<JSFunction> function = args.called_function();
// TODO(ishell): turn this back to a DCHECK. // TODO(ishell): turn this back to a DCHECK.
...@@ -1072,23 +1075,22 @@ MUST_USE_RESULT static MaybeHandle<Object> HandleApiCallHelper( ...@@ -1072,23 +1075,22 @@ MUST_USE_RESULT static MaybeHandle<Object> HandleApiCallHelper(
Handle<FunctionTemplateInfo> fun_data( Handle<FunctionTemplateInfo> fun_data(
function->shared()->get_api_func_data(), isolate); function->shared()->get_api_func_data(), isolate);
if (is_construct) { if (is_construct) {
ASSIGN_RETURN_ON_EXCEPTION( ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, fun_data, isolate, fun_data,
isolate->factory()->ConfigureInstance( isolate->factory()->ConfigureInstance(
fun_data, Handle<JSObject>::cast(args.receiver())), fun_data, Handle<JSObject>::cast(args.receiver())));
Object);
} }
DCHECK(!args[0]->IsNull()); DCHECK(!args[0]->IsNull());
if (args[0]->IsUndefined()) args[0] = function->global_proxy(); if (args[0]->IsUndefined()) args[0] = function->global_proxy();
Object* raw_holder = TypeCheck(isolate->heap(), args[0], *fun_data); Object* raw_holder = TypeCheck(heap, args[0], *fun_data);
if (raw_holder->IsNull()) { if (raw_holder->IsNull()) {
// This function cannot be called with the given receiver. Abort! // This function cannot be called with the given receiver. Abort!
THROW_NEW_ERROR( THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError("illegal_invocation", HandleVector(&function, 1)), isolate,
Object); NewTypeError("illegal_invocation", HandleVector(&function, 1)));
} }
Object* raw_call_data = fun_data->call_code(); Object* raw_call_data = fun_data->call_code();
...@@ -1100,6 +1102,7 @@ MUST_USE_RESULT static MaybeHandle<Object> HandleApiCallHelper( ...@@ -1100,6 +1102,7 @@ MUST_USE_RESULT static MaybeHandle<Object> HandleApiCallHelper(
v8::FunctionCallback callback = v8::FunctionCallback callback =
v8::ToCData<v8::FunctionCallback>(callback_obj); v8::ToCData<v8::FunctionCallback>(callback_obj);
Object* data_obj = call_data->data(); Object* data_obj = call_data->data();
Object* result;
LOG(isolate, ApiObjectAccess("call", JSObject::cast(*args.receiver()))); LOG(isolate, ApiObjectAccess("call", JSObject::cast(*args.receiver())));
DCHECK(raw_holder->IsJSObject()); DCHECK(raw_holder->IsJSObject());
...@@ -1113,73 +1116,28 @@ MUST_USE_RESULT static MaybeHandle<Object> HandleApiCallHelper( ...@@ -1113,73 +1116,28 @@ MUST_USE_RESULT static MaybeHandle<Object> HandleApiCallHelper(
is_construct); is_construct);
v8::Handle<v8::Value> value = custom.Call(callback); v8::Handle<v8::Value> value = custom.Call(callback);
Handle<Object> result;
if (value.IsEmpty()) { if (value.IsEmpty()) {
result = isolate->factory()->undefined_value(); result = heap->undefined_value();
} else { } else {
result = v8::Utils::OpenHandle(*value); result = *reinterpret_cast<Object**>(*value);
result->VerifyApiCallResultType(); result->VerifyApiCallResultType();
} }
RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate);
if (!is_construct || result->IsJSObject()) { if (!is_construct || result->IsJSObject()) return result;
return scope.CloseAndEscape(result);
}
} }
return scope.CloseAndEscape(args.receiver()); return *args.receiver();
} }
BUILTIN(HandleApiCall) { BUILTIN(HandleApiCall) {
HandleScope scope(isolate); return HandleApiCallHelper<false>(args, isolate);
DCHECK(!CalledAsConstructor(isolate));
Handle<Object> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
HandleApiCallHelper<false>(isolate, args));
return *result;
} }
BUILTIN(HandleApiCallConstruct) { BUILTIN(HandleApiCallConstruct) {
HandleScope scope(isolate); return HandleApiCallHelper<true>(args, isolate);
DCHECK(CalledAsConstructor(isolate));
Handle<Object> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
HandleApiCallHelper<true>(isolate, args));
return *result;
}
MaybeHandle<Object> Builtins::InvokeApiFunction(Handle<JSFunction> function,
Handle<Object> receiver,
int argc,
Handle<Object> args[]) {
// Construct BuiltinArguments object: function, arguments reversed, receiver.
const int kBufferSize = 32;
Object* small_argv[kBufferSize];
Object** argv;
if (argc + 2 <= kBufferSize) {
argv = small_argv;
} else {
argv = new Object* [argc + 2];
}
argv[argc + 1] = *receiver;
for (int i = 0; i < argc; ++i) {
argv[argc - i] = *args[i];
}
argv[0] = *function;
MaybeHandle<Object> result;
{
auto isolate = function->GetIsolate();
BuiltinArguments<NEEDS_CALLED_FUNCTION> arguments(argc + 2,
&argv[argc + 1]);
result = HandleApiCallHelper<false>(isolate, arguments);
}
if (argv != small_argv) {
delete[] argv;
}
return result;
} }
......
...@@ -276,10 +276,6 @@ class Builtins { ...@@ -276,10 +276,6 @@ class Builtins {
bool is_initialized() const { return initialized_; } bool is_initialized() const { return initialized_; }
MUST_USE_RESULT static MaybeHandle<Object> InvokeApiFunction(
Handle<JSFunction> function, Handle<Object> receiver, int argc,
Handle<Object> args[]);
private: private:
Builtins(); Builtins();
......
...@@ -58,26 +58,6 @@ MUST_USE_RESULT static MaybeHandle<Object> Invoke( ...@@ -58,26 +58,6 @@ MUST_USE_RESULT static MaybeHandle<Object> Invoke(
Handle<Object> args[]) { Handle<Object> args[]) {
Isolate* isolate = function->GetIsolate(); Isolate* isolate = function->GetIsolate();
// api callbacks can be called directly.
if (!is_construct && function->shared()->IsApiFunction()) {
SaveContext save(isolate);
isolate->set_context(function->context());
if (receiver->IsGlobalObject()) {
receiver = handle(Handle<GlobalObject>::cast(receiver)->global_proxy());
}
DCHECK(function->context()->global_object()->IsGlobalObject());
auto value = Builtins::InvokeApiFunction(function, receiver, argc, args);
bool has_exception = value.is_null();
DCHECK(has_exception == isolate->has_pending_exception());
if (has_exception) {
isolate->ReportPendingMessages();
return MaybeHandle<Object>();
} else {
isolate->clear_pending_message();
}
return value;
}
// Entering JavaScript. // Entering JavaScript.
VMState<JS> state(isolate); VMState<JS> state(isolate);
CHECK(AllowJavascriptExecution::IsAllowed(isolate)); CHECK(AllowJavascriptExecution::IsAllowed(isolate));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment