Home | History | Annotate | Download | only in src
      1 // Copyright 2016 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "src/api-arguments.h"
      6 
      7 #include "src/tracing/trace-event.h"
      8 #include "src/vm-state-inl.h"
      9 
     10 namespace v8 {
     11 namespace internal {
     12 
     13 #define FOR_EACH_CALLBACK_TABLE_MAPPING_1_NAME(F)                  \
     14   F(AccessorNameGetterCallback, "get", v8::Value, Object)          \
     15   F(GenericNamedPropertyQueryCallback, "has", v8::Integer, Object) \
     16   F(GenericNamedPropertyDeleterCallback, "delete", v8::Boolean, Object)
     17 
     18 #define WRITE_CALL_1_NAME(Function, type, ApiReturn, InternalReturn)          \
     19   Handle<InternalReturn> PropertyCallbackArguments::Call(Function f,          \
     20                                                          Handle<Name> name) { \
     21     Isolate* isolate = this->isolate();                                       \
     22     RuntimeCallTimerScope timer(isolate, &RuntimeCallStats::Function);        \
     23     VMState<EXTERNAL> state(isolate);                                         \
     24     ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));              \
     25     PropertyCallbackInfo<ApiReturn> info(begin());                            \
     26     LOG(isolate,                                                              \
     27         ApiNamedPropertyAccess("interceptor-named-" type, holder(), *name));  \
     28     f(v8::Utils::ToLocal(name), info);                                        \
     29     return GetReturnValue<InternalReturn>(isolate);                           \
     30   }
     31 
     32 FOR_EACH_CALLBACK_TABLE_MAPPING_1_NAME(WRITE_CALL_1_NAME)
     33 
     34 #undef FOR_EACH_CALLBACK_TABLE_MAPPING_1_NAME
     35 #undef WRITE_CALL_1_NAME
     36 
     37 #define FOR_EACH_CALLBACK_TABLE_MAPPING_1_INDEX(F)            \
     38   F(IndexedPropertyGetterCallback, "get", v8::Value, Object)  \
     39   F(IndexedPropertyQueryCallback, "has", v8::Integer, Object) \
     40   F(IndexedPropertyDeleterCallback, "delete", v8::Boolean, Object)
     41 
     42 #define WRITE_CALL_1_INDEX(Function, type, ApiReturn, InternalReturn)      \
     43   Handle<InternalReturn> PropertyCallbackArguments::Call(Function f,       \
     44                                                          uint32_t index) { \
     45     Isolate* isolate = this->isolate();                                    \
     46     RuntimeCallTimerScope timer(isolate, &RuntimeCallStats::Function);     \
     47     VMState<EXTERNAL> state(isolate);                                      \
     48     ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));           \
     49     PropertyCallbackInfo<ApiReturn> info(begin());                         \
     50     LOG(isolate, ApiIndexedPropertyAccess("interceptor-indexed-" type,     \
     51                                           holder(), index));               \
     52     f(index, info);                                                        \
     53     return GetReturnValue<InternalReturn>(isolate);                        \
     54   }
     55 
     56 FOR_EACH_CALLBACK_TABLE_MAPPING_1_INDEX(WRITE_CALL_1_INDEX)
     57 
     58 #undef FOR_EACH_CALLBACK_TABLE_MAPPING_1_INDEX
     59 #undef WRITE_CALL_1_INDEX
     60 
     61 Handle<Object> PropertyCallbackArguments::Call(
     62     GenericNamedPropertySetterCallback f, Handle<Name> name,
     63     Handle<Object> value) {
     64   Isolate* isolate = this->isolate();
     65   RuntimeCallTimerScope timer(
     66       isolate, &RuntimeCallStats::GenericNamedPropertySetterCallback);
     67   VMState<EXTERNAL> state(isolate);
     68   ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));
     69   PropertyCallbackInfo<v8::Value> info(begin());
     70   LOG(isolate,
     71       ApiNamedPropertyAccess("interceptor-named-set", holder(), *name));
     72   f(v8::Utils::ToLocal(name), v8::Utils::ToLocal(value), info);
     73   return GetReturnValue<Object>(isolate);
     74 }
     75 
     76 Handle<Object> PropertyCallbackArguments::Call(
     77     GenericNamedPropertyDefinerCallback f, Handle<Name> name,
     78     const v8::PropertyDescriptor& desc) {
     79   Isolate* isolate = this->isolate();
     80   RuntimeCallTimerScope timer(
     81       isolate, &RuntimeCallStats::GenericNamedPropertyDefinerCallback);
     82   VMState<EXTERNAL> state(isolate);
     83   ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));
     84   PropertyCallbackInfo<v8::Value> info(begin());
     85   LOG(isolate,
     86       ApiNamedPropertyAccess("interceptor-named-define", holder(), *name));
     87   f(v8::Utils::ToLocal(name), desc, info);
     88   return GetReturnValue<Object>(isolate);
     89 }
     90 
     91 Handle<Object> PropertyCallbackArguments::Call(IndexedPropertySetterCallback f,
     92                                                uint32_t index,
     93                                                Handle<Object> value) {
     94   Isolate* isolate = this->isolate();
     95   RuntimeCallTimerScope timer(isolate,
     96                               &RuntimeCallStats::IndexedPropertySetterCallback);
     97   VMState<EXTERNAL> state(isolate);
     98   ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));
     99   PropertyCallbackInfo<v8::Value> info(begin());
    100   LOG(isolate,
    101       ApiIndexedPropertyAccess("interceptor-indexed-set", holder(), index));
    102   f(index, v8::Utils::ToLocal(value), info);
    103   return GetReturnValue<Object>(isolate);
    104 }
    105 
    106 Handle<Object> PropertyCallbackArguments::Call(
    107     IndexedPropertyDefinerCallback f, uint32_t index,
    108     const v8::PropertyDescriptor& desc) {
    109   Isolate* isolate = this->isolate();
    110   RuntimeCallTimerScope timer(
    111       isolate, &RuntimeCallStats::IndexedPropertyDefinerCallback);
    112   VMState<EXTERNAL> state(isolate);
    113   ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));
    114   PropertyCallbackInfo<v8::Value> info(begin());
    115   LOG(isolate,
    116       ApiIndexedPropertyAccess("interceptor-indexed-define", holder(), index));
    117   f(index, desc, info);
    118   return GetReturnValue<Object>(isolate);
    119 }
    120 
    121 void PropertyCallbackArguments::Call(AccessorNameSetterCallback f,
    122                                      Handle<Name> name, Handle<Object> value) {
    123   Isolate* isolate = this->isolate();
    124   RuntimeCallTimerScope timer(isolate,
    125                               &RuntimeCallStats::AccessorNameSetterCallback);
    126   VMState<EXTERNAL> state(isolate);
    127   ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));
    128   PropertyCallbackInfo<void> info(begin());
    129   LOG(isolate,
    130       ApiNamedPropertyAccess("interceptor-named-set", holder(), *name));
    131   f(v8::Utils::ToLocal(name), v8::Utils::ToLocal(value), info);
    132 }
    133 
    134 }  // namespace internal
    135 }  // namespace v8
    136