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 SIDE_EFFECT_CHECK(ISOLATE, F, RETURN_TYPE)            \
     14   do {                                                        \
     15     if (ISOLATE->needs_side_effect_check() &&                 \
     16         !PerformSideEffectCheck(ISOLATE, FUNCTION_ADDR(F))) { \
     17       return Handle<RETURN_TYPE>();                           \
     18     }                                                         \
     19   } while (false)
     20 
     21 #define FOR_EACH_CALLBACK_TABLE_MAPPING_1_NAME(F)                  \
     22   F(AccessorNameGetterCallback, "get", v8::Value, Object)          \
     23   F(GenericNamedPropertyQueryCallback, "has", v8::Integer, Object) \
     24   F(GenericNamedPropertyDeleterCallback, "delete", v8::Boolean, Object)
     25 
     26 #define WRITE_CALL_1_NAME(Function, type, ApiReturn, InternalReturn)          \
     27   Handle<InternalReturn> PropertyCallbackArguments::Call(Function f,          \
     28                                                          Handle<Name> name) { \
     29     Isolate* isolate = this->isolate();                                       \
     30     SIDE_EFFECT_CHECK(isolate, f, InternalReturn);                            \
     31     RuntimeCallTimerScope timer(isolate, &RuntimeCallStats::Function);        \
     32     VMState<EXTERNAL> state(isolate);                                         \
     33     ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));              \
     34     PropertyCallbackInfo<ApiReturn> info(begin());                            \
     35     LOG(isolate,                                                              \
     36         ApiNamedPropertyAccess("interceptor-named-" type, holder(), *name));  \
     37     f(v8::Utils::ToLocal(name), info);                                        \
     38     return GetReturnValue<InternalReturn>(isolate);                           \
     39   }
     40 
     41 FOR_EACH_CALLBACK_TABLE_MAPPING_1_NAME(WRITE_CALL_1_NAME)
     42 
     43 #undef FOR_EACH_CALLBACK_TABLE_MAPPING_1_NAME
     44 #undef WRITE_CALL_1_NAME
     45 
     46 #define FOR_EACH_CALLBACK_TABLE_MAPPING_1_INDEX(F)            \
     47   F(IndexedPropertyGetterCallback, "get", v8::Value, Object)  \
     48   F(IndexedPropertyQueryCallback, "has", v8::Integer, Object) \
     49   F(IndexedPropertyDeleterCallback, "delete", v8::Boolean, Object)
     50 
     51 #define WRITE_CALL_1_INDEX(Function, type, ApiReturn, InternalReturn)      \
     52   Handle<InternalReturn> PropertyCallbackArguments::Call(Function f,       \
     53                                                          uint32_t index) { \
     54     Isolate* isolate = this->isolate();                                    \
     55     SIDE_EFFECT_CHECK(isolate, f, InternalReturn);                         \
     56     RuntimeCallTimerScope timer(isolate, &RuntimeCallStats::Function);     \
     57     VMState<EXTERNAL> state(isolate);                                      \
     58     ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));           \
     59     PropertyCallbackInfo<ApiReturn> info(begin());                         \
     60     LOG(isolate, ApiIndexedPropertyAccess("interceptor-indexed-" type,     \
     61                                           holder(), index));               \
     62     f(index, info);                                                        \
     63     return GetReturnValue<InternalReturn>(isolate);                        \
     64   }
     65 
     66 FOR_EACH_CALLBACK_TABLE_MAPPING_1_INDEX(WRITE_CALL_1_INDEX)
     67 
     68 #undef FOR_EACH_CALLBACK_TABLE_MAPPING_1_INDEX
     69 #undef WRITE_CALL_1_INDEX
     70 
     71 Handle<Object> PropertyCallbackArguments::Call(
     72     GenericNamedPropertySetterCallback f, Handle<Name> name,
     73     Handle<Object> value) {
     74   Isolate* isolate = this->isolate();
     75   SIDE_EFFECT_CHECK(isolate, f, Object);
     76   RuntimeCallTimerScope timer(
     77       isolate, &RuntimeCallStats::GenericNamedPropertySetterCallback);
     78   VMState<EXTERNAL> state(isolate);
     79   ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));
     80   PropertyCallbackInfo<v8::Value> info(begin());
     81   LOG(isolate,
     82       ApiNamedPropertyAccess("interceptor-named-set", holder(), *name));
     83   f(v8::Utils::ToLocal(name), v8::Utils::ToLocal(value), info);
     84   return GetReturnValue<Object>(isolate);
     85 }
     86 
     87 Handle<Object> PropertyCallbackArguments::Call(
     88     GenericNamedPropertyDefinerCallback f, Handle<Name> name,
     89     const v8::PropertyDescriptor& desc) {
     90   Isolate* isolate = this->isolate();
     91   SIDE_EFFECT_CHECK(isolate, f, Object);
     92   RuntimeCallTimerScope timer(
     93       isolate, &RuntimeCallStats::GenericNamedPropertyDefinerCallback);
     94   VMState<EXTERNAL> state(isolate);
     95   ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));
     96   PropertyCallbackInfo<v8::Value> info(begin());
     97   LOG(isolate,
     98       ApiNamedPropertyAccess("interceptor-named-define", holder(), *name));
     99   f(v8::Utils::ToLocal(name), desc, info);
    100   return GetReturnValue<Object>(isolate);
    101 }
    102 
    103 Handle<Object> PropertyCallbackArguments::Call(IndexedPropertySetterCallback f,
    104                                                uint32_t index,
    105                                                Handle<Object> value) {
    106   Isolate* isolate = this->isolate();
    107   SIDE_EFFECT_CHECK(isolate, f, Object);
    108   RuntimeCallTimerScope timer(isolate,
    109                               &RuntimeCallStats::IndexedPropertySetterCallback);
    110   VMState<EXTERNAL> state(isolate);
    111   ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));
    112   PropertyCallbackInfo<v8::Value> info(begin());
    113   LOG(isolate,
    114       ApiIndexedPropertyAccess("interceptor-indexed-set", holder(), index));
    115   f(index, v8::Utils::ToLocal(value), info);
    116   return GetReturnValue<Object>(isolate);
    117 }
    118 
    119 Handle<Object> PropertyCallbackArguments::Call(
    120     IndexedPropertyDefinerCallback f, uint32_t index,
    121     const v8::PropertyDescriptor& desc) {
    122   Isolate* isolate = this->isolate();
    123   SIDE_EFFECT_CHECK(isolate, f, Object);
    124   RuntimeCallTimerScope timer(
    125       isolate, &RuntimeCallStats::IndexedPropertyDefinerCallback);
    126   VMState<EXTERNAL> state(isolate);
    127   ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));
    128   PropertyCallbackInfo<v8::Value> info(begin());
    129   LOG(isolate,
    130       ApiIndexedPropertyAccess("interceptor-indexed-define", holder(), index));
    131   f(index, desc, info);
    132   return GetReturnValue<Object>(isolate);
    133 }
    134 
    135 void PropertyCallbackArguments::Call(AccessorNameSetterCallback f,
    136                                      Handle<Name> name, Handle<Object> value) {
    137   Isolate* isolate = this->isolate();
    138   if (isolate->needs_side_effect_check() &&
    139       !PerformSideEffectCheck(isolate, FUNCTION_ADDR(f))) {
    140     return;
    141   }
    142   RuntimeCallTimerScope timer(isolate,
    143                               &RuntimeCallStats::AccessorNameSetterCallback);
    144   VMState<EXTERNAL> state(isolate);
    145   ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));
    146   PropertyCallbackInfo<void> info(begin());
    147   LOG(isolate,
    148       ApiNamedPropertyAccess("interceptor-named-set", holder(), *name));
    149   f(v8::Utils::ToLocal(name), v8::Utils::ToLocal(value), info);
    150 }
    151 
    152 #undef SIDE_EFFECT_CHECK
    153 
    154 }  // namespace internal
    155 }  // namespace v8
    156