[api] Make more Callback helpers inlineable

Bug: chromium:794998
Change-Id: Ib607bc891625db686fe37cfe416c3abf4ddf9a2b
Reviewed-on: https://chromium-review.googlesource.com/983777
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52317}
This commit is contained in:
Camillo Bruni 2018-03-28 15:13:22 +02:00 committed by Commit Bot
parent b9fca91f00
commit bd93135e4e
4 changed files with 59 additions and 58 deletions

View File

@ -25,7 +25,7 @@ namespace internal {
#define PREPARE_CALLBACK_INFO(ISOLATE, F, RETURN_VALUE, API_RETURN_TYPE, \
CALLBACK_INFO) \
if (ISOLATE->needs_side_effect_check() && \
!PerformSideEffectCheck(ISOLATE, CALLBACK_INFO)) { \
!PerformSideEffectCheck(ISOLATE, *CALLBACK_INFO)) { \
return RETURN_VALUE(); \
} \
VMState<EXTERNAL> state(ISOLATE); \
@ -77,6 +77,41 @@ FOR_EACH_CALLBACK(CREATE_INDEXED_CALLBACK)
#undef FOR_EACH_CALLBACK
#undef CREATE_INDEXED_CALLBACK
Handle<Object> FunctionCallbackArguments::Call(CallHandlerInfo* handler) {
Isolate* isolate = this->isolate();
LOG(isolate, ApiObjectAccess("call", holder()));
RuntimeCallTimerScope timer(isolate, RuntimeCallCounterId::kFunctionCallback);
v8::FunctionCallback f =
v8::ToCData<v8::FunctionCallback>(handler->callback());
if (isolate->needs_side_effect_check() &&
!PerformSideEffectCheck(isolate, handler)) {
return Handle<Object>();
}
VMState<EXTERNAL> state(isolate);
ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));
FunctionCallbackInfo<v8::Value> info(begin(), argv_, argc_);
f(info);
return GetReturnValue<Object>(isolate);
}
Handle<JSObject> PropertyCallbackArguments::CallNamedEnumerator(
Handle<InterceptorInfo> interceptor) {
DCHECK(interceptor->is_named());
LOG(isolate(), ApiObjectAccess("interceptor-named-enumerator", holder()));
RuntimeCallTimerScope timer(isolate(),
RuntimeCallCounterId::kNamedEnumeratorCallback);
return CallPropertyEnumerator(interceptor);
}
Handle<JSObject> PropertyCallbackArguments::CallIndexedEnumerator(
Handle<InterceptorInfo> interceptor) {
DCHECK(!interceptor->is_named());
LOG(isolate(), ApiObjectAccess("interceptor-indexed-enumerator", holder()));
RuntimeCallTimerScope timer(isolate(),
RuntimeCallCounterId::kIndexedEnumeratorCallback);
return CallPropertyEnumerator(interceptor);
}
Handle<Object> PropertyCallbackArguments::CallNamedGetter(
Handle<InterceptorInfo> interceptor, Handle<Name> name) {
DCHECK_NAME_COMPATIBLE(interceptor, name);

View File

@ -13,46 +13,12 @@
namespace v8 {
namespace internal {
Handle<Object> FunctionCallbackArguments::Call(CallHandlerInfo* handler) {
Isolate* isolate = this->isolate();
LOG(isolate, ApiObjectAccess("call", holder()));
RuntimeCallTimerScope timer(isolate, RuntimeCallCounterId::kFunctionCallback);
v8::FunctionCallback f =
v8::ToCData<v8::FunctionCallback>(handler->callback());
if (isolate->needs_side_effect_check() &&
!isolate->debug()->PerformSideEffectCheckForCallback(handler)) {
return Handle<Object>();
}
VMState<EXTERNAL> state(isolate);
ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));
FunctionCallbackInfo<v8::Value> info(begin(), argv_, argc_);
f(info);
return GetReturnValue<Object>(isolate);
}
Handle<JSObject> PropertyCallbackArguments::CallNamedEnumerator(
Handle<InterceptorInfo> interceptor) {
DCHECK(interceptor->is_named());
LOG(isolate(), ApiObjectAccess("interceptor-named-enumerator", holder()));
RuntimeCallTimerScope timer(isolate(),
RuntimeCallCounterId::kNamedEnumeratorCallback);
return CallPropertyEnumerator(interceptor);
}
Handle<JSObject> PropertyCallbackArguments::CallIndexedEnumerator(
Handle<InterceptorInfo> interceptor) {
DCHECK(!interceptor->is_named());
LOG(isolate(), ApiObjectAccess("interceptor-indexed-enumerator", holder()));
RuntimeCallTimerScope timer(isolate(),
RuntimeCallCounterId::kIndexedEnumeratorCallback);
return CallPropertyEnumerator(interceptor);
}
bool PropertyCallbackArguments::PerformSideEffectCheck(
Isolate* isolate, Handle<Object> callback_info) {
// static
bool CustomArgumentsBase ::PerformSideEffectCheck(Isolate* isolate,
Object* callback_info) {
// TODO(7515): always pass a valid callback info object.
if (callback_info.is_null()) return false;
return isolate->debug()->PerformSideEffectCheckForCallback(*callback_info);
if (callback_info == nullptr) return false;
return isolate->debug()->PerformSideEffectCheckForCallback(callback_info);
}
} // namespace internal

View File

@ -15,34 +15,31 @@ namespace internal {
// Custom arguments replicate a small segment of stack that can be
// accessed through an Arguments object the same way the actual stack
// can.
template <int kArrayLength>
class CustomArgumentsBase : public Relocatable {
public:
virtual inline void IterateInstance(RootVisitor* v) {
v->VisitRootPointers(Root::kRelocatable, nullptr, values_,
values_ + kArrayLength);
}
protected:
inline Object** begin() { return values_; }
explicit inline CustomArgumentsBase(Isolate* isolate)
: Relocatable(isolate) {}
Object* values_[kArrayLength];
static bool PerformSideEffectCheck(Isolate* isolate, Object* callback_info);
};
template <typename T>
class CustomArguments : public CustomArgumentsBase<T::kArgsLength> {
class CustomArguments : public CustomArgumentsBase {
public:
static const int kReturnValueOffset = T::kReturnValueIndex;
typedef CustomArgumentsBase<T::kArgsLength> Super;
~CustomArguments() {
this->begin()[kReturnValueOffset] =
reinterpret_cast<Object*>(kHandleZapValue);
}
virtual inline void IterateInstance(RootVisitor* v) {
v->VisitRootPointers(Root::kRelocatable, nullptr, values_,
values_ + T::kArgsLength);
}
protected:
explicit inline CustomArguments(Isolate* isolate) : Super(isolate) {}
explicit inline CustomArguments(Isolate* isolate)
: CustomArgumentsBase(isolate) {}
template <typename V>
Handle<V> GetReturnValue(Isolate* isolate);
@ -50,6 +47,9 @@ class CustomArguments : public CustomArgumentsBase<T::kArgsLength> {
inline Isolate* isolate() {
return reinterpret_cast<Isolate*>(this->begin()[T::kIsolateIndex]);
}
inline Object** begin() { return values_; }
Object* values_[T::kArgsLength];
};
template <typename T>
@ -126,7 +126,8 @@ class PropertyCallbackArguments
Handle<Name> name);
inline Handle<Object> CallNamedDescriptor(Handle<InterceptorInfo> interceptor,
Handle<Name> name);
Handle<JSObject> CallNamedEnumerator(Handle<InterceptorInfo> interceptor);
inline Handle<JSObject> CallNamedEnumerator(
Handle<InterceptorInfo> interceptor);
// -------------------------------------------------------------------------
// Indexed Interceptor Callbacks
@ -143,7 +144,8 @@ class PropertyCallbackArguments
uint32_t index);
inline Handle<Object> CallIndexedDescriptor(
Handle<InterceptorInfo> interceptor, uint32_t index);
Handle<JSObject> CallIndexedEnumerator(Handle<InterceptorInfo> interceptor);
inline Handle<JSObject> CallIndexedEnumerator(
Handle<InterceptorInfo> interceptor);
private:
/*
@ -167,8 +169,6 @@ class PropertyCallbackArguments
return JSObject::cast(this->begin()[T::kHolderIndex]);
}
bool PerformSideEffectCheck(Isolate* isolate, Handle<Object> callback_info);
// Don't copy PropertyCallbackArguments, because they would both have the
// same prev_ pointer.
DISALLOW_COPY_AND_ASSIGN(PropertyCallbackArguments);
@ -215,7 +215,7 @@ class FunctionCallbackArguments
* and used if it's been set to anything inside the callback.
* New style callbacks always use the return value.
*/
Handle<Object> Call(CallHandlerInfo* handler);
inline Handle<Object> Call(CallHandlerInfo* handler);
private:
inline JSObject* holder() {

View File

@ -4,7 +4,7 @@
#include "src/builtins/builtins.h"
#include "src/api-arguments.h"
#include "src/api-arguments-inl.h"
#include "src/api-natives.h"
#include "src/builtins/builtins-utils.h"
#include "src/counters.h"