11cb0ef41Sopenharmony_ci// Copyright 2021 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef INCLUDE_V8_TEMPLATE_H_
61cb0ef41Sopenharmony_ci#define INCLUDE_V8_TEMPLATE_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "v8-data.h"               // NOLINT(build/include_directory)
91cb0ef41Sopenharmony_ci#include "v8-function-callback.h"  // NOLINT(build/include_directory)
101cb0ef41Sopenharmony_ci#include "v8-local-handle.h"       // NOLINT(build/include_directory)
111cb0ef41Sopenharmony_ci#include "v8-memory-span.h"        // NOLINT(build/include_directory)
121cb0ef41Sopenharmony_ci#include "v8-object.h"             // NOLINT(build/include_directory)
131cb0ef41Sopenharmony_ci#include "v8config.h"              // NOLINT(build/include_directory)
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_cinamespace v8 {
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciclass AccessorSignature;
181cb0ef41Sopenharmony_ciclass CFunction;
191cb0ef41Sopenharmony_ciclass FunctionTemplate;
201cb0ef41Sopenharmony_ciclass ObjectTemplate;
211cb0ef41Sopenharmony_ciclass Signature;
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci// --- Templates ---
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci#define V8_INTRINSICS_LIST(F)                                 \
261cb0ef41Sopenharmony_ci  F(ArrayProto_entries, array_entries_iterator)               \
271cb0ef41Sopenharmony_ci  F(ArrayProto_forEach, array_for_each_iterator)              \
281cb0ef41Sopenharmony_ci  F(ArrayProto_keys, array_keys_iterator)                     \
291cb0ef41Sopenharmony_ci  F(ArrayProto_values, array_values_iterator)                 \
301cb0ef41Sopenharmony_ci  F(ArrayPrototype, initial_array_prototype)                  \
311cb0ef41Sopenharmony_ci  F(AsyncIteratorPrototype, initial_async_iterator_prototype) \
321cb0ef41Sopenharmony_ci  F(ErrorPrototype, initial_error_prototype)                  \
331cb0ef41Sopenharmony_ci  F(IteratorPrototype, initial_iterator_prototype)            \
341cb0ef41Sopenharmony_ci  F(ObjProto_valueOf, object_value_of_function)
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_cienum Intrinsic {
371cb0ef41Sopenharmony_ci#define V8_DECL_INTRINSIC(name, iname) k##name,
381cb0ef41Sopenharmony_ci  V8_INTRINSICS_LIST(V8_DECL_INTRINSIC)
391cb0ef41Sopenharmony_ci#undef V8_DECL_INTRINSIC
401cb0ef41Sopenharmony_ci};
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci/**
431cb0ef41Sopenharmony_ci * The superclass of object and function templates.
441cb0ef41Sopenharmony_ci */
451cb0ef41Sopenharmony_ciclass V8_EXPORT Template : public Data {
461cb0ef41Sopenharmony_ci public:
471cb0ef41Sopenharmony_ci  /**
481cb0ef41Sopenharmony_ci   * Adds a property to each instance created by this template.
491cb0ef41Sopenharmony_ci   *
501cb0ef41Sopenharmony_ci   * The property must be defined either as a primitive value, or a template.
511cb0ef41Sopenharmony_ci   */
521cb0ef41Sopenharmony_ci  void Set(Local<Name> name, Local<Data> value,
531cb0ef41Sopenharmony_ci           PropertyAttribute attributes = None);
541cb0ef41Sopenharmony_ci  void SetPrivate(Local<Private> name, Local<Data> value,
551cb0ef41Sopenharmony_ci                  PropertyAttribute attributes = None);
561cb0ef41Sopenharmony_ci  V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value,
571cb0ef41Sopenharmony_ci                     PropertyAttribute attributes = None);
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci  void SetAccessorProperty(
601cb0ef41Sopenharmony_ci      Local<Name> name,
611cb0ef41Sopenharmony_ci      Local<FunctionTemplate> getter = Local<FunctionTemplate>(),
621cb0ef41Sopenharmony_ci      Local<FunctionTemplate> setter = Local<FunctionTemplate>(),
631cb0ef41Sopenharmony_ci      PropertyAttribute attribute = None, AccessControl settings = DEFAULT);
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ci  /**
661cb0ef41Sopenharmony_ci   * Whenever the property with the given name is accessed on objects
671cb0ef41Sopenharmony_ci   * created from this Template the getter and setter callbacks
681cb0ef41Sopenharmony_ci   * are called instead of getting and setting the property directly
691cb0ef41Sopenharmony_ci   * on the JavaScript object.
701cb0ef41Sopenharmony_ci   *
711cb0ef41Sopenharmony_ci   * \param name The name of the property for which an accessor is added.
721cb0ef41Sopenharmony_ci   * \param getter The callback to invoke when getting the property.
731cb0ef41Sopenharmony_ci   * \param setter The callback to invoke when setting the property.
741cb0ef41Sopenharmony_ci   * \param data A piece of data that will be passed to the getter and setter
751cb0ef41Sopenharmony_ci   *   callbacks whenever they are invoked.
761cb0ef41Sopenharmony_ci   * \param settings Access control settings for the accessor. This is a bit
771cb0ef41Sopenharmony_ci   *   field consisting of one of more of
781cb0ef41Sopenharmony_ci   *   DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2.
791cb0ef41Sopenharmony_ci   *   The default is to not allow cross-context access.
801cb0ef41Sopenharmony_ci   *   ALL_CAN_READ means that all cross-context reads are allowed.
811cb0ef41Sopenharmony_ci   *   ALL_CAN_WRITE means that all cross-context writes are allowed.
821cb0ef41Sopenharmony_ci   *   The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all
831cb0ef41Sopenharmony_ci   *   cross-context access.
841cb0ef41Sopenharmony_ci   * \param attribute The attributes of the property for which an accessor
851cb0ef41Sopenharmony_ci   *   is added.
861cb0ef41Sopenharmony_ci   * \param signature The signature describes valid receivers for the accessor
871cb0ef41Sopenharmony_ci   *   and is used to perform implicit instance checks against them. If the
881cb0ef41Sopenharmony_ci   *   receiver is incompatible (i.e. is not an instance of the constructor as
891cb0ef41Sopenharmony_ci   *   defined by FunctionTemplate::HasInstance()), an implicit TypeError is
901cb0ef41Sopenharmony_ci   *   thrown and no callback is invoked.
911cb0ef41Sopenharmony_ci   */
921cb0ef41Sopenharmony_ci  V8_DEPRECATED("Do signature check in accessor")
931cb0ef41Sopenharmony_ci  void SetNativeDataProperty(
941cb0ef41Sopenharmony_ci      Local<String> name, AccessorGetterCallback getter,
951cb0ef41Sopenharmony_ci      AccessorSetterCallback setter, Local<Value> data,
961cb0ef41Sopenharmony_ci      PropertyAttribute attribute, Local<AccessorSignature> signature,
971cb0ef41Sopenharmony_ci      AccessControl settings = DEFAULT,
981cb0ef41Sopenharmony_ci      SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
991cb0ef41Sopenharmony_ci      SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
1001cb0ef41Sopenharmony_ci  V8_DEPRECATED("Do signature check in accessor")
1011cb0ef41Sopenharmony_ci  void SetNativeDataProperty(
1021cb0ef41Sopenharmony_ci      Local<Name> name, AccessorNameGetterCallback getter,
1031cb0ef41Sopenharmony_ci      AccessorNameSetterCallback setter, Local<Value> data,
1041cb0ef41Sopenharmony_ci      PropertyAttribute attribute, Local<AccessorSignature> signature,
1051cb0ef41Sopenharmony_ci      AccessControl settings = DEFAULT,
1061cb0ef41Sopenharmony_ci      SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
1071cb0ef41Sopenharmony_ci      SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
1081cb0ef41Sopenharmony_ci  void SetNativeDataProperty(
1091cb0ef41Sopenharmony_ci      Local<String> name, AccessorGetterCallback getter,
1101cb0ef41Sopenharmony_ci      AccessorSetterCallback setter = nullptr,
1111cb0ef41Sopenharmony_ci      Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
1121cb0ef41Sopenharmony_ci      AccessControl settings = DEFAULT,
1131cb0ef41Sopenharmony_ci      SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
1141cb0ef41Sopenharmony_ci      SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
1151cb0ef41Sopenharmony_ci  void SetNativeDataProperty(
1161cb0ef41Sopenharmony_ci      Local<Name> name, AccessorNameGetterCallback getter,
1171cb0ef41Sopenharmony_ci      AccessorNameSetterCallback setter = nullptr,
1181cb0ef41Sopenharmony_ci      Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
1191cb0ef41Sopenharmony_ci      AccessControl settings = DEFAULT,
1201cb0ef41Sopenharmony_ci      SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
1211cb0ef41Sopenharmony_ci      SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
1221cb0ef41Sopenharmony_ci
1231cb0ef41Sopenharmony_ci  /**
1241cb0ef41Sopenharmony_ci   * Like SetNativeDataProperty, but V8 will replace the native data property
1251cb0ef41Sopenharmony_ci   * with a real data property on first access.
1261cb0ef41Sopenharmony_ci   */
1271cb0ef41Sopenharmony_ci  void SetLazyDataProperty(
1281cb0ef41Sopenharmony_ci      Local<Name> name, AccessorNameGetterCallback getter,
1291cb0ef41Sopenharmony_ci      Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
1301cb0ef41Sopenharmony_ci      SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
1311cb0ef41Sopenharmony_ci      SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
1321cb0ef41Sopenharmony_ci
1331cb0ef41Sopenharmony_ci  /**
1341cb0ef41Sopenharmony_ci   * During template instantiation, sets the value with the intrinsic property
1351cb0ef41Sopenharmony_ci   * from the correct context.
1361cb0ef41Sopenharmony_ci   */
1371cb0ef41Sopenharmony_ci  void SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic,
1381cb0ef41Sopenharmony_ci                                PropertyAttribute attribute = None);
1391cb0ef41Sopenharmony_ci
1401cb0ef41Sopenharmony_ci private:
1411cb0ef41Sopenharmony_ci  Template();
1421cb0ef41Sopenharmony_ci
1431cb0ef41Sopenharmony_ci  friend class ObjectTemplate;
1441cb0ef41Sopenharmony_ci  friend class FunctionTemplate;
1451cb0ef41Sopenharmony_ci};
1461cb0ef41Sopenharmony_ci
1471cb0ef41Sopenharmony_ci// TODO(dcarney): Replace GenericNamedPropertyFooCallback with just
1481cb0ef41Sopenharmony_ci// NamedPropertyFooCallback.
1491cb0ef41Sopenharmony_ci
1501cb0ef41Sopenharmony_ci/**
1511cb0ef41Sopenharmony_ci * Interceptor for get requests on an object.
1521cb0ef41Sopenharmony_ci *
1531cb0ef41Sopenharmony_ci * Use `info.GetReturnValue().Set()` to set the return value of the
1541cb0ef41Sopenharmony_ci * intercepted get request.
1551cb0ef41Sopenharmony_ci *
1561cb0ef41Sopenharmony_ci * \param property The name of the property for which the request was
1571cb0ef41Sopenharmony_ci * intercepted.
1581cb0ef41Sopenharmony_ci * \param info Information about the intercepted request, such as
1591cb0ef41Sopenharmony_ci * isolate, receiver, return value, or whether running in `'use strict`' mode.
1601cb0ef41Sopenharmony_ci * See `PropertyCallbackInfo`.
1611cb0ef41Sopenharmony_ci *
1621cb0ef41Sopenharmony_ci * \code
1631cb0ef41Sopenharmony_ci *  void GetterCallback(
1641cb0ef41Sopenharmony_ci *    Local<Name> name,
1651cb0ef41Sopenharmony_ci *    const v8::PropertyCallbackInfo<v8::Value>& info) {
1661cb0ef41Sopenharmony_ci *      info.GetReturnValue().Set(v8_num(42));
1671cb0ef41Sopenharmony_ci *  }
1681cb0ef41Sopenharmony_ci *
1691cb0ef41Sopenharmony_ci *  v8::Local<v8::FunctionTemplate> templ =
1701cb0ef41Sopenharmony_ci *      v8::FunctionTemplate::New(isolate);
1711cb0ef41Sopenharmony_ci *  templ->InstanceTemplate()->SetHandler(
1721cb0ef41Sopenharmony_ci *      v8::NamedPropertyHandlerConfiguration(GetterCallback));
1731cb0ef41Sopenharmony_ci *  LocalContext env;
1741cb0ef41Sopenharmony_ci *  env->Global()
1751cb0ef41Sopenharmony_ci *      ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local())
1761cb0ef41Sopenharmony_ci *                                             .ToLocalChecked()
1771cb0ef41Sopenharmony_ci *                                             ->NewInstance(env.local())
1781cb0ef41Sopenharmony_ci *                                             .ToLocalChecked())
1791cb0ef41Sopenharmony_ci *      .FromJust();
1801cb0ef41Sopenharmony_ci *  v8::Local<v8::Value> result = CompileRun("obj.a = 17; obj.a");
1811cb0ef41Sopenharmony_ci *  CHECK(v8_num(42)->Equals(env.local(), result).FromJust());
1821cb0ef41Sopenharmony_ci * \endcode
1831cb0ef41Sopenharmony_ci *
1841cb0ef41Sopenharmony_ci * See also `ObjectTemplate::SetHandler`.
1851cb0ef41Sopenharmony_ci */
1861cb0ef41Sopenharmony_ciusing GenericNamedPropertyGetterCallback =
1871cb0ef41Sopenharmony_ci    void (*)(Local<Name> property, const PropertyCallbackInfo<Value>& info);
1881cb0ef41Sopenharmony_ci
1891cb0ef41Sopenharmony_ci/**
1901cb0ef41Sopenharmony_ci * Interceptor for set requests on an object.
1911cb0ef41Sopenharmony_ci *
1921cb0ef41Sopenharmony_ci * Use `info.GetReturnValue()` to indicate whether the request was intercepted
1931cb0ef41Sopenharmony_ci * or not. If the setter successfully intercepts the request, i.e., if the
1941cb0ef41Sopenharmony_ci * request should not be further executed, call
1951cb0ef41Sopenharmony_ci * `info.GetReturnValue().Set(value)`. If the setter
1961cb0ef41Sopenharmony_ci * did not intercept the request, i.e., if the request should be handled as
1971cb0ef41Sopenharmony_ci * if no interceptor is present, do not not call `Set()`.
1981cb0ef41Sopenharmony_ci *
1991cb0ef41Sopenharmony_ci * \param property The name of the property for which the request was
2001cb0ef41Sopenharmony_ci * intercepted.
2011cb0ef41Sopenharmony_ci * \param value The value which the property will have if the request
2021cb0ef41Sopenharmony_ci * is not intercepted.
2031cb0ef41Sopenharmony_ci * \param info Information about the intercepted request, such as
2041cb0ef41Sopenharmony_ci * isolate, receiver, return value, or whether running in `'use strict'` mode.
2051cb0ef41Sopenharmony_ci * See `PropertyCallbackInfo`.
2061cb0ef41Sopenharmony_ci *
2071cb0ef41Sopenharmony_ci * See also
2081cb0ef41Sopenharmony_ci * `ObjectTemplate::SetHandler.`
2091cb0ef41Sopenharmony_ci */
2101cb0ef41Sopenharmony_ciusing GenericNamedPropertySetterCallback =
2111cb0ef41Sopenharmony_ci    void (*)(Local<Name> property, Local<Value> value,
2121cb0ef41Sopenharmony_ci             const PropertyCallbackInfo<Value>& info);
2131cb0ef41Sopenharmony_ci
2141cb0ef41Sopenharmony_ci/**
2151cb0ef41Sopenharmony_ci * Intercepts all requests that query the attributes of the
2161cb0ef41Sopenharmony_ci * property, e.g., getOwnPropertyDescriptor(), propertyIsEnumerable(), and
2171cb0ef41Sopenharmony_ci * defineProperty().
2181cb0ef41Sopenharmony_ci *
2191cb0ef41Sopenharmony_ci * Use `info.GetReturnValue().Set(value)` to set the property attributes. The
2201cb0ef41Sopenharmony_ci * value is an integer encoding a `v8::PropertyAttribute`.
2211cb0ef41Sopenharmony_ci *
2221cb0ef41Sopenharmony_ci * \param property The name of the property for which the request was
2231cb0ef41Sopenharmony_ci * intercepted.
2241cb0ef41Sopenharmony_ci * \param info Information about the intercepted request, such as
2251cb0ef41Sopenharmony_ci * isolate, receiver, return value, or whether running in `'use strict'` mode.
2261cb0ef41Sopenharmony_ci * See `PropertyCallbackInfo`.
2271cb0ef41Sopenharmony_ci *
2281cb0ef41Sopenharmony_ci * \note Some functions query the property attributes internally, even though
2291cb0ef41Sopenharmony_ci * they do not return the attributes. For example, `hasOwnProperty()` can
2301cb0ef41Sopenharmony_ci * trigger this interceptor depending on the state of the object.
2311cb0ef41Sopenharmony_ci *
2321cb0ef41Sopenharmony_ci * See also
2331cb0ef41Sopenharmony_ci * `ObjectTemplate::SetHandler.`
2341cb0ef41Sopenharmony_ci */
2351cb0ef41Sopenharmony_ciusing GenericNamedPropertyQueryCallback =
2361cb0ef41Sopenharmony_ci    void (*)(Local<Name> property, const PropertyCallbackInfo<Integer>& info);
2371cb0ef41Sopenharmony_ci
2381cb0ef41Sopenharmony_ci/**
2391cb0ef41Sopenharmony_ci * Interceptor for delete requests on an object.
2401cb0ef41Sopenharmony_ci *
2411cb0ef41Sopenharmony_ci * Use `info.GetReturnValue()` to indicate whether the request was intercepted
2421cb0ef41Sopenharmony_ci * or not. If the deleter successfully intercepts the request, i.e., if the
2431cb0ef41Sopenharmony_ci * request should not be further executed, call
2441cb0ef41Sopenharmony_ci * `info.GetReturnValue().Set(value)` with a boolean `value`. The `value` is
2451cb0ef41Sopenharmony_ci * used as the return value of `delete`.
2461cb0ef41Sopenharmony_ci *
2471cb0ef41Sopenharmony_ci * \param property The name of the property for which the request was
2481cb0ef41Sopenharmony_ci * intercepted.
2491cb0ef41Sopenharmony_ci * \param info Information about the intercepted request, such as
2501cb0ef41Sopenharmony_ci * isolate, receiver, return value, or whether running in `'use strict'` mode.
2511cb0ef41Sopenharmony_ci * See `PropertyCallbackInfo`.
2521cb0ef41Sopenharmony_ci *
2531cb0ef41Sopenharmony_ci * \note If you need to mimic the behavior of `delete`, i.e., throw in strict
2541cb0ef41Sopenharmony_ci * mode instead of returning false, use `info.ShouldThrowOnError()` to determine
2551cb0ef41Sopenharmony_ci * if you are in strict mode.
2561cb0ef41Sopenharmony_ci *
2571cb0ef41Sopenharmony_ci * See also `ObjectTemplate::SetHandler.`
2581cb0ef41Sopenharmony_ci */
2591cb0ef41Sopenharmony_ciusing GenericNamedPropertyDeleterCallback =
2601cb0ef41Sopenharmony_ci    void (*)(Local<Name> property, const PropertyCallbackInfo<Boolean>& info);
2611cb0ef41Sopenharmony_ci
2621cb0ef41Sopenharmony_ci/**
2631cb0ef41Sopenharmony_ci * Returns an array containing the names of the properties the named
2641cb0ef41Sopenharmony_ci * property getter intercepts.
2651cb0ef41Sopenharmony_ci *
2661cb0ef41Sopenharmony_ci * Note: The values in the array must be of type v8::Name.
2671cb0ef41Sopenharmony_ci */
2681cb0ef41Sopenharmony_ciusing GenericNamedPropertyEnumeratorCallback =
2691cb0ef41Sopenharmony_ci    void (*)(const PropertyCallbackInfo<Array>& info);
2701cb0ef41Sopenharmony_ci
2711cb0ef41Sopenharmony_ci/**
2721cb0ef41Sopenharmony_ci * Interceptor for defineProperty requests on an object.
2731cb0ef41Sopenharmony_ci *
2741cb0ef41Sopenharmony_ci * Use `info.GetReturnValue()` to indicate whether the request was intercepted
2751cb0ef41Sopenharmony_ci * or not. If the definer successfully intercepts the request, i.e., if the
2761cb0ef41Sopenharmony_ci * request should not be further executed, call
2771cb0ef41Sopenharmony_ci * `info.GetReturnValue().Set(value)`. If the definer
2781cb0ef41Sopenharmony_ci * did not intercept the request, i.e., if the request should be handled as
2791cb0ef41Sopenharmony_ci * if no interceptor is present, do not not call `Set()`.
2801cb0ef41Sopenharmony_ci *
2811cb0ef41Sopenharmony_ci * \param property The name of the property for which the request was
2821cb0ef41Sopenharmony_ci * intercepted.
2831cb0ef41Sopenharmony_ci * \param desc The property descriptor which is used to define the
2841cb0ef41Sopenharmony_ci * property if the request is not intercepted.
2851cb0ef41Sopenharmony_ci * \param info Information about the intercepted request, such as
2861cb0ef41Sopenharmony_ci * isolate, receiver, return value, or whether running in `'use strict'` mode.
2871cb0ef41Sopenharmony_ci * See `PropertyCallbackInfo`.
2881cb0ef41Sopenharmony_ci *
2891cb0ef41Sopenharmony_ci * See also `ObjectTemplate::SetHandler`.
2901cb0ef41Sopenharmony_ci */
2911cb0ef41Sopenharmony_ciusing GenericNamedPropertyDefinerCallback =
2921cb0ef41Sopenharmony_ci    void (*)(Local<Name> property, const PropertyDescriptor& desc,
2931cb0ef41Sopenharmony_ci             const PropertyCallbackInfo<Value>& info);
2941cb0ef41Sopenharmony_ci
2951cb0ef41Sopenharmony_ci/**
2961cb0ef41Sopenharmony_ci * Interceptor for getOwnPropertyDescriptor requests on an object.
2971cb0ef41Sopenharmony_ci *
2981cb0ef41Sopenharmony_ci * Use `info.GetReturnValue().Set()` to set the return value of the
2991cb0ef41Sopenharmony_ci * intercepted request. The return value must be an object that
3001cb0ef41Sopenharmony_ci * can be converted to a PropertyDescriptor, e.g., a `v8::value` returned from
3011cb0ef41Sopenharmony_ci * `v8::Object::getOwnPropertyDescriptor`.
3021cb0ef41Sopenharmony_ci *
3031cb0ef41Sopenharmony_ci * \param property The name of the property for which the request was
3041cb0ef41Sopenharmony_ci * intercepted.
3051cb0ef41Sopenharmony_ci * \info Information about the intercepted request, such as
3061cb0ef41Sopenharmony_ci * isolate, receiver, return value, or whether running in `'use strict'` mode.
3071cb0ef41Sopenharmony_ci * See `PropertyCallbackInfo`.
3081cb0ef41Sopenharmony_ci *
3091cb0ef41Sopenharmony_ci * \note If GetOwnPropertyDescriptor is intercepted, it will
3101cb0ef41Sopenharmony_ci * always return true, i.e., indicate that the property was found.
3111cb0ef41Sopenharmony_ci *
3121cb0ef41Sopenharmony_ci * See also `ObjectTemplate::SetHandler`.
3131cb0ef41Sopenharmony_ci */
3141cb0ef41Sopenharmony_ciusing GenericNamedPropertyDescriptorCallback =
3151cb0ef41Sopenharmony_ci    void (*)(Local<Name> property, const PropertyCallbackInfo<Value>& info);
3161cb0ef41Sopenharmony_ci
3171cb0ef41Sopenharmony_ci/**
3181cb0ef41Sopenharmony_ci * See `v8::GenericNamedPropertyGetterCallback`.
3191cb0ef41Sopenharmony_ci */
3201cb0ef41Sopenharmony_ciusing IndexedPropertyGetterCallback =
3211cb0ef41Sopenharmony_ci    void (*)(uint32_t index, const PropertyCallbackInfo<Value>& info);
3221cb0ef41Sopenharmony_ci
3231cb0ef41Sopenharmony_ci/**
3241cb0ef41Sopenharmony_ci * See `v8::GenericNamedPropertySetterCallback`.
3251cb0ef41Sopenharmony_ci */
3261cb0ef41Sopenharmony_ciusing IndexedPropertySetterCallback =
3271cb0ef41Sopenharmony_ci    void (*)(uint32_t index, Local<Value> value,
3281cb0ef41Sopenharmony_ci             const PropertyCallbackInfo<Value>& info);
3291cb0ef41Sopenharmony_ci
3301cb0ef41Sopenharmony_ci/**
3311cb0ef41Sopenharmony_ci * See `v8::GenericNamedPropertyQueryCallback`.
3321cb0ef41Sopenharmony_ci */
3331cb0ef41Sopenharmony_ciusing IndexedPropertyQueryCallback =
3341cb0ef41Sopenharmony_ci    void (*)(uint32_t index, const PropertyCallbackInfo<Integer>& info);
3351cb0ef41Sopenharmony_ci
3361cb0ef41Sopenharmony_ci/**
3371cb0ef41Sopenharmony_ci * See `v8::GenericNamedPropertyDeleterCallback`.
3381cb0ef41Sopenharmony_ci */
3391cb0ef41Sopenharmony_ciusing IndexedPropertyDeleterCallback =
3401cb0ef41Sopenharmony_ci    void (*)(uint32_t index, const PropertyCallbackInfo<Boolean>& info);
3411cb0ef41Sopenharmony_ci
3421cb0ef41Sopenharmony_ci/**
3431cb0ef41Sopenharmony_ci * Returns an array containing the indices of the properties the indexed
3441cb0ef41Sopenharmony_ci * property getter intercepts.
3451cb0ef41Sopenharmony_ci *
3461cb0ef41Sopenharmony_ci * Note: The values in the array must be uint32_t.
3471cb0ef41Sopenharmony_ci */
3481cb0ef41Sopenharmony_ciusing IndexedPropertyEnumeratorCallback =
3491cb0ef41Sopenharmony_ci    void (*)(const PropertyCallbackInfo<Array>& info);
3501cb0ef41Sopenharmony_ci
3511cb0ef41Sopenharmony_ci/**
3521cb0ef41Sopenharmony_ci * See `v8::GenericNamedPropertyDefinerCallback`.
3531cb0ef41Sopenharmony_ci */
3541cb0ef41Sopenharmony_ciusing IndexedPropertyDefinerCallback =
3551cb0ef41Sopenharmony_ci    void (*)(uint32_t index, const PropertyDescriptor& desc,
3561cb0ef41Sopenharmony_ci             const PropertyCallbackInfo<Value>& info);
3571cb0ef41Sopenharmony_ci
3581cb0ef41Sopenharmony_ci/**
3591cb0ef41Sopenharmony_ci * See `v8::GenericNamedPropertyDescriptorCallback`.
3601cb0ef41Sopenharmony_ci */
3611cb0ef41Sopenharmony_ciusing IndexedPropertyDescriptorCallback =
3621cb0ef41Sopenharmony_ci    void (*)(uint32_t index, const PropertyCallbackInfo<Value>& info);
3631cb0ef41Sopenharmony_ci
3641cb0ef41Sopenharmony_ci/**
3651cb0ef41Sopenharmony_ci * Returns true if the given context should be allowed to access the given
3661cb0ef41Sopenharmony_ci * object.
3671cb0ef41Sopenharmony_ci */
3681cb0ef41Sopenharmony_ciusing AccessCheckCallback = bool (*)(Local<Context> accessing_context,
3691cb0ef41Sopenharmony_ci                                     Local<Object> accessed_object,
3701cb0ef41Sopenharmony_ci                                     Local<Value> data);
3711cb0ef41Sopenharmony_ci
3721cb0ef41Sopenharmony_cienum class ConstructorBehavior { kThrow, kAllow };
3731cb0ef41Sopenharmony_ci
3741cb0ef41Sopenharmony_ci/**
3751cb0ef41Sopenharmony_ci * A FunctionTemplate is used to create functions at runtime. There
3761cb0ef41Sopenharmony_ci * can only be one function created from a FunctionTemplate in a
3771cb0ef41Sopenharmony_ci * context.  The lifetime of the created function is equal to the
3781cb0ef41Sopenharmony_ci * lifetime of the context.  So in case the embedder needs to create
3791cb0ef41Sopenharmony_ci * temporary functions that can be collected using Scripts is
3801cb0ef41Sopenharmony_ci * preferred.
3811cb0ef41Sopenharmony_ci *
3821cb0ef41Sopenharmony_ci * Any modification of a FunctionTemplate after first instantiation will trigger
3831cb0ef41Sopenharmony_ci * a crash.
3841cb0ef41Sopenharmony_ci *
3851cb0ef41Sopenharmony_ci * A FunctionTemplate can have properties, these properties are added to the
3861cb0ef41Sopenharmony_ci * function object when it is created.
3871cb0ef41Sopenharmony_ci *
3881cb0ef41Sopenharmony_ci * A FunctionTemplate has a corresponding instance template which is
3891cb0ef41Sopenharmony_ci * used to create object instances when the function is used as a
3901cb0ef41Sopenharmony_ci * constructor. Properties added to the instance template are added to
3911cb0ef41Sopenharmony_ci * each object instance.
3921cb0ef41Sopenharmony_ci *
3931cb0ef41Sopenharmony_ci * A FunctionTemplate can have a prototype template. The prototype template
3941cb0ef41Sopenharmony_ci * is used to create the prototype object of the function.
3951cb0ef41Sopenharmony_ci *
3961cb0ef41Sopenharmony_ci * The following example shows how to use a FunctionTemplate:
3971cb0ef41Sopenharmony_ci *
3981cb0ef41Sopenharmony_ci * \code
3991cb0ef41Sopenharmony_ci *    v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
4001cb0ef41Sopenharmony_ci *    t->Set(isolate, "func_property", v8::Number::New(isolate, 1));
4011cb0ef41Sopenharmony_ci *
4021cb0ef41Sopenharmony_ci *    v8::Local<v8::Template> proto_t = t->PrototypeTemplate();
4031cb0ef41Sopenharmony_ci *    proto_t->Set(isolate,
4041cb0ef41Sopenharmony_ci *                 "proto_method",
4051cb0ef41Sopenharmony_ci *                 v8::FunctionTemplate::New(isolate, InvokeCallback));
4061cb0ef41Sopenharmony_ci *    proto_t->Set(isolate, "proto_const", v8::Number::New(isolate, 2));
4071cb0ef41Sopenharmony_ci *
4081cb0ef41Sopenharmony_ci *    v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate();
4091cb0ef41Sopenharmony_ci *    instance_t->SetAccessor(
4101cb0ef41Sopenharmony_ci          String::NewFromUtf8Literal(isolate, "instance_accessor"),
4111cb0ef41Sopenharmony_ci *        InstanceAccessorCallback);
4121cb0ef41Sopenharmony_ci *    instance_t->SetHandler(
4131cb0ef41Sopenharmony_ci *        NamedPropertyHandlerConfiguration(PropertyHandlerCallback));
4141cb0ef41Sopenharmony_ci *    instance_t->Set(String::NewFromUtf8Literal(isolate, "instance_property"),
4151cb0ef41Sopenharmony_ci *                    Number::New(isolate, 3));
4161cb0ef41Sopenharmony_ci *
4171cb0ef41Sopenharmony_ci *    v8::Local<v8::Function> function = t->GetFunction();
4181cb0ef41Sopenharmony_ci *    v8::Local<v8::Object> instance = function->NewInstance();
4191cb0ef41Sopenharmony_ci * \endcode
4201cb0ef41Sopenharmony_ci *
4211cb0ef41Sopenharmony_ci * Let's use "function" as the JS variable name of the function object
4221cb0ef41Sopenharmony_ci * and "instance" for the instance object created above.  The function
4231cb0ef41Sopenharmony_ci * and the instance will have the following properties:
4241cb0ef41Sopenharmony_ci *
4251cb0ef41Sopenharmony_ci * \code
4261cb0ef41Sopenharmony_ci *   func_property in function == true;
4271cb0ef41Sopenharmony_ci *   function.func_property == 1;
4281cb0ef41Sopenharmony_ci *
4291cb0ef41Sopenharmony_ci *   function.prototype.proto_method() invokes 'InvokeCallback'
4301cb0ef41Sopenharmony_ci *   function.prototype.proto_const == 2;
4311cb0ef41Sopenharmony_ci *
4321cb0ef41Sopenharmony_ci *   instance instanceof function == true;
4331cb0ef41Sopenharmony_ci *   instance.instance_accessor calls 'InstanceAccessorCallback'
4341cb0ef41Sopenharmony_ci *   instance.instance_property == 3;
4351cb0ef41Sopenharmony_ci * \endcode
4361cb0ef41Sopenharmony_ci *
4371cb0ef41Sopenharmony_ci * A FunctionTemplate can inherit from another one by calling the
4381cb0ef41Sopenharmony_ci * FunctionTemplate::Inherit method.  The following graph illustrates
4391cb0ef41Sopenharmony_ci * the semantics of inheritance:
4401cb0ef41Sopenharmony_ci *
4411cb0ef41Sopenharmony_ci * \code
4421cb0ef41Sopenharmony_ci *   FunctionTemplate Parent  -> Parent() . prototype -> { }
4431cb0ef41Sopenharmony_ci *     ^                                                  ^
4441cb0ef41Sopenharmony_ci *     | Inherit(Parent)                                  | .__proto__
4451cb0ef41Sopenharmony_ci *     |                                                  |
4461cb0ef41Sopenharmony_ci *   FunctionTemplate Child   -> Child()  . prototype -> { }
4471cb0ef41Sopenharmony_ci * \endcode
4481cb0ef41Sopenharmony_ci *
4491cb0ef41Sopenharmony_ci * A FunctionTemplate 'Child' inherits from 'Parent', the prototype
4501cb0ef41Sopenharmony_ci * object of the Child() function has __proto__ pointing to the
4511cb0ef41Sopenharmony_ci * Parent() function's prototype object. An instance of the Child
4521cb0ef41Sopenharmony_ci * function has all properties on Parent's instance templates.
4531cb0ef41Sopenharmony_ci *
4541cb0ef41Sopenharmony_ci * Let Parent be the FunctionTemplate initialized in the previous
4551cb0ef41Sopenharmony_ci * section and create a Child FunctionTemplate by:
4561cb0ef41Sopenharmony_ci *
4571cb0ef41Sopenharmony_ci * \code
4581cb0ef41Sopenharmony_ci *   Local<FunctionTemplate> parent = t;
4591cb0ef41Sopenharmony_ci *   Local<FunctionTemplate> child = FunctionTemplate::New();
4601cb0ef41Sopenharmony_ci *   child->Inherit(parent);
4611cb0ef41Sopenharmony_ci *
4621cb0ef41Sopenharmony_ci *   Local<Function> child_function = child->GetFunction();
4631cb0ef41Sopenharmony_ci *   Local<Object> child_instance = child_function->NewInstance();
4641cb0ef41Sopenharmony_ci * \endcode
4651cb0ef41Sopenharmony_ci *
4661cb0ef41Sopenharmony_ci * The Child function and Child instance will have the following
4671cb0ef41Sopenharmony_ci * properties:
4681cb0ef41Sopenharmony_ci *
4691cb0ef41Sopenharmony_ci * \code
4701cb0ef41Sopenharmony_ci *   child_func.prototype.__proto__ == function.prototype;
4711cb0ef41Sopenharmony_ci *   child_instance.instance_accessor calls 'InstanceAccessorCallback'
4721cb0ef41Sopenharmony_ci *   child_instance.instance_property == 3;
4731cb0ef41Sopenharmony_ci * \endcode
4741cb0ef41Sopenharmony_ci *
4751cb0ef41Sopenharmony_ci * The additional 'c_function' parameter refers to a fast API call, which
4761cb0ef41Sopenharmony_ci * must not trigger GC or JavaScript execution, or call into V8 in other
4771cb0ef41Sopenharmony_ci * ways. For more information how to define them, see
4781cb0ef41Sopenharmony_ci * include/v8-fast-api-calls.h. Please note that this feature is still
4791cb0ef41Sopenharmony_ci * experimental.
4801cb0ef41Sopenharmony_ci */
4811cb0ef41Sopenharmony_ciclass V8_EXPORT FunctionTemplate : public Template {
4821cb0ef41Sopenharmony_ci public:
4831cb0ef41Sopenharmony_ci  /** Creates a function template.*/
4841cb0ef41Sopenharmony_ci  static Local<FunctionTemplate> New(
4851cb0ef41Sopenharmony_ci      Isolate* isolate, FunctionCallback callback = nullptr,
4861cb0ef41Sopenharmony_ci      Local<Value> data = Local<Value>(),
4871cb0ef41Sopenharmony_ci      Local<Signature> signature = Local<Signature>(), int length = 0,
4881cb0ef41Sopenharmony_ci      ConstructorBehavior behavior = ConstructorBehavior::kAllow,
4891cb0ef41Sopenharmony_ci      SideEffectType side_effect_type = SideEffectType::kHasSideEffect,
4901cb0ef41Sopenharmony_ci      const CFunction* c_function = nullptr, uint16_t instance_type = 0,
4911cb0ef41Sopenharmony_ci      uint16_t allowed_receiver_instance_type_range_start = 0,
4921cb0ef41Sopenharmony_ci      uint16_t allowed_receiver_instance_type_range_end = 0);
4931cb0ef41Sopenharmony_ci
4941cb0ef41Sopenharmony_ci  /** Creates a function template for multiple overloaded fast API calls.*/
4951cb0ef41Sopenharmony_ci  static Local<FunctionTemplate> NewWithCFunctionOverloads(
4961cb0ef41Sopenharmony_ci      Isolate* isolate, FunctionCallback callback = nullptr,
4971cb0ef41Sopenharmony_ci      Local<Value> data = Local<Value>(),
4981cb0ef41Sopenharmony_ci      Local<Signature> signature = Local<Signature>(), int length = 0,
4991cb0ef41Sopenharmony_ci      ConstructorBehavior behavior = ConstructorBehavior::kAllow,
5001cb0ef41Sopenharmony_ci      SideEffectType side_effect_type = SideEffectType::kHasSideEffect,
5011cb0ef41Sopenharmony_ci      const MemorySpan<const CFunction>& c_function_overloads = {});
5021cb0ef41Sopenharmony_ci
5031cb0ef41Sopenharmony_ci  /**
5041cb0ef41Sopenharmony_ci   * Creates a function template backed/cached by a private property.
5051cb0ef41Sopenharmony_ci   */
5061cb0ef41Sopenharmony_ci  static Local<FunctionTemplate> NewWithCache(
5071cb0ef41Sopenharmony_ci      Isolate* isolate, FunctionCallback callback,
5081cb0ef41Sopenharmony_ci      Local<Private> cache_property, Local<Value> data = Local<Value>(),
5091cb0ef41Sopenharmony_ci      Local<Signature> signature = Local<Signature>(), int length = 0,
5101cb0ef41Sopenharmony_ci      SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5111cb0ef41Sopenharmony_ci
5121cb0ef41Sopenharmony_ci  /** Returns the unique function instance in the current execution context.*/
5131cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT MaybeLocal<Function> GetFunction(
5141cb0ef41Sopenharmony_ci      Local<Context> context);
5151cb0ef41Sopenharmony_ci
5161cb0ef41Sopenharmony_ci  /**
5171cb0ef41Sopenharmony_ci   * Similar to Context::NewRemoteContext, this creates an instance that
5181cb0ef41Sopenharmony_ci   * isn't backed by an actual object.
5191cb0ef41Sopenharmony_ci   *
5201cb0ef41Sopenharmony_ci   * The InstanceTemplate of this FunctionTemplate must have access checks with
5211cb0ef41Sopenharmony_ci   * handlers installed.
5221cb0ef41Sopenharmony_ci   */
5231cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewRemoteInstance();
5241cb0ef41Sopenharmony_ci
5251cb0ef41Sopenharmony_ci  /**
5261cb0ef41Sopenharmony_ci   * Set the call-handler callback for a FunctionTemplate.  This
5271cb0ef41Sopenharmony_ci   * callback is called whenever the function created from this
5281cb0ef41Sopenharmony_ci   * FunctionTemplate is called. The 'c_function' represents a fast
5291cb0ef41Sopenharmony_ci   * API call, see the comment above the class declaration.
5301cb0ef41Sopenharmony_ci   */
5311cb0ef41Sopenharmony_ci  void SetCallHandler(
5321cb0ef41Sopenharmony_ci      FunctionCallback callback, Local<Value> data = Local<Value>(),
5331cb0ef41Sopenharmony_ci      SideEffectType side_effect_type = SideEffectType::kHasSideEffect,
5341cb0ef41Sopenharmony_ci      const MemorySpan<const CFunction>& c_function_overloads = {});
5351cb0ef41Sopenharmony_ci
5361cb0ef41Sopenharmony_ci  /** Set the predefined length property for the FunctionTemplate. */
5371cb0ef41Sopenharmony_ci  void SetLength(int length);
5381cb0ef41Sopenharmony_ci
5391cb0ef41Sopenharmony_ci  /** Get the InstanceTemplate. */
5401cb0ef41Sopenharmony_ci  Local<ObjectTemplate> InstanceTemplate();
5411cb0ef41Sopenharmony_ci
5421cb0ef41Sopenharmony_ci  /**
5431cb0ef41Sopenharmony_ci   * Causes the function template to inherit from a parent function template.
5441cb0ef41Sopenharmony_ci   * This means the function's prototype.__proto__ is set to the parent
5451cb0ef41Sopenharmony_ci   * function's prototype.
5461cb0ef41Sopenharmony_ci   **/
5471cb0ef41Sopenharmony_ci  void Inherit(Local<FunctionTemplate> parent);
5481cb0ef41Sopenharmony_ci
5491cb0ef41Sopenharmony_ci  /**
5501cb0ef41Sopenharmony_ci   * A PrototypeTemplate is the template used to create the prototype object
5511cb0ef41Sopenharmony_ci   * of the function created by this template.
5521cb0ef41Sopenharmony_ci   */
5531cb0ef41Sopenharmony_ci  Local<ObjectTemplate> PrototypeTemplate();
5541cb0ef41Sopenharmony_ci
5551cb0ef41Sopenharmony_ci  /**
5561cb0ef41Sopenharmony_ci   * A PrototypeProviderTemplate is another function template whose prototype
5571cb0ef41Sopenharmony_ci   * property is used for this template. This is mutually exclusive with setting
5581cb0ef41Sopenharmony_ci   * a prototype template indirectly by calling PrototypeTemplate() or using
5591cb0ef41Sopenharmony_ci   * Inherit().
5601cb0ef41Sopenharmony_ci   **/
5611cb0ef41Sopenharmony_ci  void SetPrototypeProviderTemplate(Local<FunctionTemplate> prototype_provider);
5621cb0ef41Sopenharmony_ci
5631cb0ef41Sopenharmony_ci  /**
5641cb0ef41Sopenharmony_ci   * Set the class name of the FunctionTemplate.  This is used for
5651cb0ef41Sopenharmony_ci   * printing objects created with the function created from the
5661cb0ef41Sopenharmony_ci   * FunctionTemplate as its constructor.
5671cb0ef41Sopenharmony_ci   */
5681cb0ef41Sopenharmony_ci  void SetClassName(Local<String> name);
5691cb0ef41Sopenharmony_ci
5701cb0ef41Sopenharmony_ci  /**
5711cb0ef41Sopenharmony_ci   * When set to true, no access check will be performed on the receiver of a
5721cb0ef41Sopenharmony_ci   * function call.  Currently defaults to true, but this is subject to change.
5731cb0ef41Sopenharmony_ci   */
5741cb0ef41Sopenharmony_ci  void SetAcceptAnyReceiver(bool value);
5751cb0ef41Sopenharmony_ci
5761cb0ef41Sopenharmony_ci  /**
5771cb0ef41Sopenharmony_ci   * Sets the ReadOnly flag in the attributes of the 'prototype' property
5781cb0ef41Sopenharmony_ci   * of functions created from this FunctionTemplate to true.
5791cb0ef41Sopenharmony_ci   */
5801cb0ef41Sopenharmony_ci  void ReadOnlyPrototype();
5811cb0ef41Sopenharmony_ci
5821cb0ef41Sopenharmony_ci  /**
5831cb0ef41Sopenharmony_ci   * Removes the prototype property from functions created from this
5841cb0ef41Sopenharmony_ci   * FunctionTemplate.
5851cb0ef41Sopenharmony_ci   */
5861cb0ef41Sopenharmony_ci  void RemovePrototype();
5871cb0ef41Sopenharmony_ci
5881cb0ef41Sopenharmony_ci  /**
5891cb0ef41Sopenharmony_ci   * Returns true if the given object is an instance of this function
5901cb0ef41Sopenharmony_ci   * template.
5911cb0ef41Sopenharmony_ci   */
5921cb0ef41Sopenharmony_ci  bool HasInstance(Local<Value> object);
5931cb0ef41Sopenharmony_ci
5941cb0ef41Sopenharmony_ci  /**
5951cb0ef41Sopenharmony_ci   * Returns true if the given value is an API object that was constructed by an
5961cb0ef41Sopenharmony_ci   * instance of this function template (without checking for inheriting
5971cb0ef41Sopenharmony_ci   * function templates).
5981cb0ef41Sopenharmony_ci   *
5991cb0ef41Sopenharmony_ci   * This is an experimental feature and may still change significantly.
6001cb0ef41Sopenharmony_ci   */
6011cb0ef41Sopenharmony_ci  bool IsLeafTemplateForApiObject(v8::Local<v8::Value> value) const;
6021cb0ef41Sopenharmony_ci
6031cb0ef41Sopenharmony_ci  V8_INLINE static FunctionTemplate* Cast(Data* data);
6041cb0ef41Sopenharmony_ci
6051cb0ef41Sopenharmony_ci private:
6061cb0ef41Sopenharmony_ci  FunctionTemplate();
6071cb0ef41Sopenharmony_ci
6081cb0ef41Sopenharmony_ci  static void CheckCast(Data* that);
6091cb0ef41Sopenharmony_ci  friend class Context;
6101cb0ef41Sopenharmony_ci  friend class ObjectTemplate;
6111cb0ef41Sopenharmony_ci};
6121cb0ef41Sopenharmony_ci
6131cb0ef41Sopenharmony_ci/**
6141cb0ef41Sopenharmony_ci * Configuration flags for v8::NamedPropertyHandlerConfiguration or
6151cb0ef41Sopenharmony_ci * v8::IndexedPropertyHandlerConfiguration.
6161cb0ef41Sopenharmony_ci */
6171cb0ef41Sopenharmony_cienum class PropertyHandlerFlags {
6181cb0ef41Sopenharmony_ci  /**
6191cb0ef41Sopenharmony_ci   * None.
6201cb0ef41Sopenharmony_ci   */
6211cb0ef41Sopenharmony_ci  kNone = 0,
6221cb0ef41Sopenharmony_ci
6231cb0ef41Sopenharmony_ci  /**
6241cb0ef41Sopenharmony_ci   * See ALL_CAN_READ above.
6251cb0ef41Sopenharmony_ci   */
6261cb0ef41Sopenharmony_ci  kAllCanRead = 1,
6271cb0ef41Sopenharmony_ci
6281cb0ef41Sopenharmony_ci  /** Will not call into interceptor for properties on the receiver or prototype
6291cb0ef41Sopenharmony_ci   * chain, i.e., only call into interceptor for properties that do not exist.
6301cb0ef41Sopenharmony_ci   * Currently only valid for named interceptors.
6311cb0ef41Sopenharmony_ci   */
6321cb0ef41Sopenharmony_ci  kNonMasking = 1 << 1,
6331cb0ef41Sopenharmony_ci
6341cb0ef41Sopenharmony_ci  /**
6351cb0ef41Sopenharmony_ci   * Will not call into interceptor for symbol lookup.  Only meaningful for
6361cb0ef41Sopenharmony_ci   * named interceptors.
6371cb0ef41Sopenharmony_ci   */
6381cb0ef41Sopenharmony_ci  kOnlyInterceptStrings = 1 << 2,
6391cb0ef41Sopenharmony_ci
6401cb0ef41Sopenharmony_ci  /**
6411cb0ef41Sopenharmony_ci   * The getter, query, enumerator callbacks do not produce side effects.
6421cb0ef41Sopenharmony_ci   */
6431cb0ef41Sopenharmony_ci  kHasNoSideEffect = 1 << 3,
6441cb0ef41Sopenharmony_ci};
6451cb0ef41Sopenharmony_ci
6461cb0ef41Sopenharmony_cistruct NamedPropertyHandlerConfiguration {
6471cb0ef41Sopenharmony_ci  NamedPropertyHandlerConfiguration(
6481cb0ef41Sopenharmony_ci      GenericNamedPropertyGetterCallback getter,
6491cb0ef41Sopenharmony_ci      GenericNamedPropertySetterCallback setter,
6501cb0ef41Sopenharmony_ci      GenericNamedPropertyQueryCallback query,
6511cb0ef41Sopenharmony_ci      GenericNamedPropertyDeleterCallback deleter,
6521cb0ef41Sopenharmony_ci      GenericNamedPropertyEnumeratorCallback enumerator,
6531cb0ef41Sopenharmony_ci      GenericNamedPropertyDefinerCallback definer,
6541cb0ef41Sopenharmony_ci      GenericNamedPropertyDescriptorCallback descriptor,
6551cb0ef41Sopenharmony_ci      Local<Value> data = Local<Value>(),
6561cb0ef41Sopenharmony_ci      PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
6571cb0ef41Sopenharmony_ci      : getter(getter),
6581cb0ef41Sopenharmony_ci        setter(setter),
6591cb0ef41Sopenharmony_ci        query(query),
6601cb0ef41Sopenharmony_ci        deleter(deleter),
6611cb0ef41Sopenharmony_ci        enumerator(enumerator),
6621cb0ef41Sopenharmony_ci        definer(definer),
6631cb0ef41Sopenharmony_ci        descriptor(descriptor),
6641cb0ef41Sopenharmony_ci        data(data),
6651cb0ef41Sopenharmony_ci        flags(flags) {}
6661cb0ef41Sopenharmony_ci
6671cb0ef41Sopenharmony_ci  NamedPropertyHandlerConfiguration(
6681cb0ef41Sopenharmony_ci      /** Note: getter is required */
6691cb0ef41Sopenharmony_ci      GenericNamedPropertyGetterCallback getter = nullptr,
6701cb0ef41Sopenharmony_ci      GenericNamedPropertySetterCallback setter = nullptr,
6711cb0ef41Sopenharmony_ci      GenericNamedPropertyQueryCallback query = nullptr,
6721cb0ef41Sopenharmony_ci      GenericNamedPropertyDeleterCallback deleter = nullptr,
6731cb0ef41Sopenharmony_ci      GenericNamedPropertyEnumeratorCallback enumerator = nullptr,
6741cb0ef41Sopenharmony_ci      Local<Value> data = Local<Value>(),
6751cb0ef41Sopenharmony_ci      PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
6761cb0ef41Sopenharmony_ci      : getter(getter),
6771cb0ef41Sopenharmony_ci        setter(setter),
6781cb0ef41Sopenharmony_ci        query(query),
6791cb0ef41Sopenharmony_ci        deleter(deleter),
6801cb0ef41Sopenharmony_ci        enumerator(enumerator),
6811cb0ef41Sopenharmony_ci        definer(nullptr),
6821cb0ef41Sopenharmony_ci        descriptor(nullptr),
6831cb0ef41Sopenharmony_ci        data(data),
6841cb0ef41Sopenharmony_ci        flags(flags) {}
6851cb0ef41Sopenharmony_ci
6861cb0ef41Sopenharmony_ci  NamedPropertyHandlerConfiguration(
6871cb0ef41Sopenharmony_ci      GenericNamedPropertyGetterCallback getter,
6881cb0ef41Sopenharmony_ci      GenericNamedPropertySetterCallback setter,
6891cb0ef41Sopenharmony_ci      GenericNamedPropertyDescriptorCallback descriptor,
6901cb0ef41Sopenharmony_ci      GenericNamedPropertyDeleterCallback deleter,
6911cb0ef41Sopenharmony_ci      GenericNamedPropertyEnumeratorCallback enumerator,
6921cb0ef41Sopenharmony_ci      GenericNamedPropertyDefinerCallback definer,
6931cb0ef41Sopenharmony_ci      Local<Value> data = Local<Value>(),
6941cb0ef41Sopenharmony_ci      PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
6951cb0ef41Sopenharmony_ci      : getter(getter),
6961cb0ef41Sopenharmony_ci        setter(setter),
6971cb0ef41Sopenharmony_ci        query(nullptr),
6981cb0ef41Sopenharmony_ci        deleter(deleter),
6991cb0ef41Sopenharmony_ci        enumerator(enumerator),
7001cb0ef41Sopenharmony_ci        definer(definer),
7011cb0ef41Sopenharmony_ci        descriptor(descriptor),
7021cb0ef41Sopenharmony_ci        data(data),
7031cb0ef41Sopenharmony_ci        flags(flags) {}
7041cb0ef41Sopenharmony_ci
7051cb0ef41Sopenharmony_ci  GenericNamedPropertyGetterCallback getter;
7061cb0ef41Sopenharmony_ci  GenericNamedPropertySetterCallback setter;
7071cb0ef41Sopenharmony_ci  GenericNamedPropertyQueryCallback query;
7081cb0ef41Sopenharmony_ci  GenericNamedPropertyDeleterCallback deleter;
7091cb0ef41Sopenharmony_ci  GenericNamedPropertyEnumeratorCallback enumerator;
7101cb0ef41Sopenharmony_ci  GenericNamedPropertyDefinerCallback definer;
7111cb0ef41Sopenharmony_ci  GenericNamedPropertyDescriptorCallback descriptor;
7121cb0ef41Sopenharmony_ci  Local<Value> data;
7131cb0ef41Sopenharmony_ci  PropertyHandlerFlags flags;
7141cb0ef41Sopenharmony_ci};
7151cb0ef41Sopenharmony_ci
7161cb0ef41Sopenharmony_cistruct IndexedPropertyHandlerConfiguration {
7171cb0ef41Sopenharmony_ci  IndexedPropertyHandlerConfiguration(
7181cb0ef41Sopenharmony_ci      IndexedPropertyGetterCallback getter,
7191cb0ef41Sopenharmony_ci      IndexedPropertySetterCallback setter, IndexedPropertyQueryCallback query,
7201cb0ef41Sopenharmony_ci      IndexedPropertyDeleterCallback deleter,
7211cb0ef41Sopenharmony_ci      IndexedPropertyEnumeratorCallback enumerator,
7221cb0ef41Sopenharmony_ci      IndexedPropertyDefinerCallback definer,
7231cb0ef41Sopenharmony_ci      IndexedPropertyDescriptorCallback descriptor,
7241cb0ef41Sopenharmony_ci      Local<Value> data = Local<Value>(),
7251cb0ef41Sopenharmony_ci      PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
7261cb0ef41Sopenharmony_ci      : getter(getter),
7271cb0ef41Sopenharmony_ci        setter(setter),
7281cb0ef41Sopenharmony_ci        query(query),
7291cb0ef41Sopenharmony_ci        deleter(deleter),
7301cb0ef41Sopenharmony_ci        enumerator(enumerator),
7311cb0ef41Sopenharmony_ci        definer(definer),
7321cb0ef41Sopenharmony_ci        descriptor(descriptor),
7331cb0ef41Sopenharmony_ci        data(data),
7341cb0ef41Sopenharmony_ci        flags(flags) {}
7351cb0ef41Sopenharmony_ci
7361cb0ef41Sopenharmony_ci  IndexedPropertyHandlerConfiguration(
7371cb0ef41Sopenharmony_ci      /** Note: getter is required */
7381cb0ef41Sopenharmony_ci      IndexedPropertyGetterCallback getter = nullptr,
7391cb0ef41Sopenharmony_ci      IndexedPropertySetterCallback setter = nullptr,
7401cb0ef41Sopenharmony_ci      IndexedPropertyQueryCallback query = nullptr,
7411cb0ef41Sopenharmony_ci      IndexedPropertyDeleterCallback deleter = nullptr,
7421cb0ef41Sopenharmony_ci      IndexedPropertyEnumeratorCallback enumerator = nullptr,
7431cb0ef41Sopenharmony_ci      Local<Value> data = Local<Value>(),
7441cb0ef41Sopenharmony_ci      PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
7451cb0ef41Sopenharmony_ci      : getter(getter),
7461cb0ef41Sopenharmony_ci        setter(setter),
7471cb0ef41Sopenharmony_ci        query(query),
7481cb0ef41Sopenharmony_ci        deleter(deleter),
7491cb0ef41Sopenharmony_ci        enumerator(enumerator),
7501cb0ef41Sopenharmony_ci        definer(nullptr),
7511cb0ef41Sopenharmony_ci        descriptor(nullptr),
7521cb0ef41Sopenharmony_ci        data(data),
7531cb0ef41Sopenharmony_ci        flags(flags) {}
7541cb0ef41Sopenharmony_ci
7551cb0ef41Sopenharmony_ci  IndexedPropertyHandlerConfiguration(
7561cb0ef41Sopenharmony_ci      IndexedPropertyGetterCallback getter,
7571cb0ef41Sopenharmony_ci      IndexedPropertySetterCallback setter,
7581cb0ef41Sopenharmony_ci      IndexedPropertyDescriptorCallback descriptor,
7591cb0ef41Sopenharmony_ci      IndexedPropertyDeleterCallback deleter,
7601cb0ef41Sopenharmony_ci      IndexedPropertyEnumeratorCallback enumerator,
7611cb0ef41Sopenharmony_ci      IndexedPropertyDefinerCallback definer,
7621cb0ef41Sopenharmony_ci      Local<Value> data = Local<Value>(),
7631cb0ef41Sopenharmony_ci      PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
7641cb0ef41Sopenharmony_ci      : getter(getter),
7651cb0ef41Sopenharmony_ci        setter(setter),
7661cb0ef41Sopenharmony_ci        query(nullptr),
7671cb0ef41Sopenharmony_ci        deleter(deleter),
7681cb0ef41Sopenharmony_ci        enumerator(enumerator),
7691cb0ef41Sopenharmony_ci        definer(definer),
7701cb0ef41Sopenharmony_ci        descriptor(descriptor),
7711cb0ef41Sopenharmony_ci        data(data),
7721cb0ef41Sopenharmony_ci        flags(flags) {}
7731cb0ef41Sopenharmony_ci
7741cb0ef41Sopenharmony_ci  IndexedPropertyGetterCallback getter;
7751cb0ef41Sopenharmony_ci  IndexedPropertySetterCallback setter;
7761cb0ef41Sopenharmony_ci  IndexedPropertyQueryCallback query;
7771cb0ef41Sopenharmony_ci  IndexedPropertyDeleterCallback deleter;
7781cb0ef41Sopenharmony_ci  IndexedPropertyEnumeratorCallback enumerator;
7791cb0ef41Sopenharmony_ci  IndexedPropertyDefinerCallback definer;
7801cb0ef41Sopenharmony_ci  IndexedPropertyDescriptorCallback descriptor;
7811cb0ef41Sopenharmony_ci  Local<Value> data;
7821cb0ef41Sopenharmony_ci  PropertyHandlerFlags flags;
7831cb0ef41Sopenharmony_ci};
7841cb0ef41Sopenharmony_ci
7851cb0ef41Sopenharmony_ci/**
7861cb0ef41Sopenharmony_ci * An ObjectTemplate is used to create objects at runtime.
7871cb0ef41Sopenharmony_ci *
7881cb0ef41Sopenharmony_ci * Properties added to an ObjectTemplate are added to each object
7891cb0ef41Sopenharmony_ci * created from the ObjectTemplate.
7901cb0ef41Sopenharmony_ci */
7911cb0ef41Sopenharmony_ciclass V8_EXPORT ObjectTemplate : public Template {
7921cb0ef41Sopenharmony_ci public:
7931cb0ef41Sopenharmony_ci  /** Creates an ObjectTemplate. */
7941cb0ef41Sopenharmony_ci  static Local<ObjectTemplate> New(
7951cb0ef41Sopenharmony_ci      Isolate* isolate,
7961cb0ef41Sopenharmony_ci      Local<FunctionTemplate> constructor = Local<FunctionTemplate>());
7971cb0ef41Sopenharmony_ci
7981cb0ef41Sopenharmony_ci  /** Creates a new instance of this template.*/
7991cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(Local<Context> context);
8001cb0ef41Sopenharmony_ci
8011cb0ef41Sopenharmony_ci  /**
8021cb0ef41Sopenharmony_ci   * Sets an accessor on the object template.
8031cb0ef41Sopenharmony_ci   *
8041cb0ef41Sopenharmony_ci   * Whenever the property with the given name is accessed on objects
8051cb0ef41Sopenharmony_ci   * created from this ObjectTemplate the getter and setter callbacks
8061cb0ef41Sopenharmony_ci   * are called instead of getting and setting the property directly
8071cb0ef41Sopenharmony_ci   * on the JavaScript object.
8081cb0ef41Sopenharmony_ci   *
8091cb0ef41Sopenharmony_ci   * \param name The name of the property for which an accessor is added.
8101cb0ef41Sopenharmony_ci   * \param getter The callback to invoke when getting the property.
8111cb0ef41Sopenharmony_ci   * \param setter The callback to invoke when setting the property.
8121cb0ef41Sopenharmony_ci   * \param data A piece of data that will be passed to the getter and setter
8131cb0ef41Sopenharmony_ci   *   callbacks whenever they are invoked.
8141cb0ef41Sopenharmony_ci   * \param settings Access control settings for the accessor. This is a bit
8151cb0ef41Sopenharmony_ci   *   field consisting of one of more of
8161cb0ef41Sopenharmony_ci   *   DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2.
8171cb0ef41Sopenharmony_ci   *   The default is to not allow cross-context access.
8181cb0ef41Sopenharmony_ci   *   ALL_CAN_READ means that all cross-context reads are allowed.
8191cb0ef41Sopenharmony_ci   *   ALL_CAN_WRITE means that all cross-context writes are allowed.
8201cb0ef41Sopenharmony_ci   *   The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all
8211cb0ef41Sopenharmony_ci   *   cross-context access.
8221cb0ef41Sopenharmony_ci   * \param attribute The attributes of the property for which an accessor
8231cb0ef41Sopenharmony_ci   *   is added.
8241cb0ef41Sopenharmony_ci   * \param signature The signature describes valid receivers for the accessor
8251cb0ef41Sopenharmony_ci   *   and is used to perform implicit instance checks against them. If the
8261cb0ef41Sopenharmony_ci   *   receiver is incompatible (i.e. is not an instance of the constructor as
8271cb0ef41Sopenharmony_ci   *   defined by FunctionTemplate::HasInstance()), an implicit TypeError is
8281cb0ef41Sopenharmony_ci   *   thrown and no callback is invoked.
8291cb0ef41Sopenharmony_ci   */
8301cb0ef41Sopenharmony_ci  V8_DEPRECATED("Do signature check in accessor")
8311cb0ef41Sopenharmony_ci  void SetAccessor(
8321cb0ef41Sopenharmony_ci      Local<String> name, AccessorGetterCallback getter,
8331cb0ef41Sopenharmony_ci      AccessorSetterCallback setter, Local<Value> data, AccessControl settings,
8341cb0ef41Sopenharmony_ci      PropertyAttribute attribute, Local<AccessorSignature> signature,
8351cb0ef41Sopenharmony_ci      SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
8361cb0ef41Sopenharmony_ci      SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
8371cb0ef41Sopenharmony_ci  V8_DEPRECATED("Do signature check in accessor")
8381cb0ef41Sopenharmony_ci  void SetAccessor(
8391cb0ef41Sopenharmony_ci      Local<Name> name, AccessorNameGetterCallback getter,
8401cb0ef41Sopenharmony_ci      AccessorNameSetterCallback setter, Local<Value> data,
8411cb0ef41Sopenharmony_ci      AccessControl settings, PropertyAttribute attribute,
8421cb0ef41Sopenharmony_ci      Local<AccessorSignature> signature,
8431cb0ef41Sopenharmony_ci      SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
8441cb0ef41Sopenharmony_ci      SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
8451cb0ef41Sopenharmony_ci  void SetAccessor(
8461cb0ef41Sopenharmony_ci      Local<String> name, AccessorGetterCallback getter,
8471cb0ef41Sopenharmony_ci      AccessorSetterCallback setter = nullptr,
8481cb0ef41Sopenharmony_ci      Local<Value> data = Local<Value>(), AccessControl settings = DEFAULT,
8491cb0ef41Sopenharmony_ci      PropertyAttribute attribute = None,
8501cb0ef41Sopenharmony_ci      SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
8511cb0ef41Sopenharmony_ci      SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
8521cb0ef41Sopenharmony_ci  void SetAccessor(
8531cb0ef41Sopenharmony_ci      Local<Name> name, AccessorNameGetterCallback getter,
8541cb0ef41Sopenharmony_ci      AccessorNameSetterCallback setter = nullptr,
8551cb0ef41Sopenharmony_ci      Local<Value> data = Local<Value>(), AccessControl settings = DEFAULT,
8561cb0ef41Sopenharmony_ci      PropertyAttribute attribute = None,
8571cb0ef41Sopenharmony_ci      SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
8581cb0ef41Sopenharmony_ci      SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
8591cb0ef41Sopenharmony_ci
8601cb0ef41Sopenharmony_ci  /**
8611cb0ef41Sopenharmony_ci   * Sets a named property handler on the object template.
8621cb0ef41Sopenharmony_ci   *
8631cb0ef41Sopenharmony_ci   * Whenever a property whose name is a string or a symbol is accessed on
8641cb0ef41Sopenharmony_ci   * objects created from this object template, the provided callback is
8651cb0ef41Sopenharmony_ci   * invoked instead of accessing the property directly on the JavaScript
8661cb0ef41Sopenharmony_ci   * object.
8671cb0ef41Sopenharmony_ci   *
8681cb0ef41Sopenharmony_ci   * @param configuration The NamedPropertyHandlerConfiguration that defines the
8691cb0ef41Sopenharmony_ci   * callbacks to invoke when accessing a property.
8701cb0ef41Sopenharmony_ci   */
8711cb0ef41Sopenharmony_ci  void SetHandler(const NamedPropertyHandlerConfiguration& configuration);
8721cb0ef41Sopenharmony_ci
8731cb0ef41Sopenharmony_ci  /**
8741cb0ef41Sopenharmony_ci   * Sets an indexed property handler on the object template.
8751cb0ef41Sopenharmony_ci   *
8761cb0ef41Sopenharmony_ci   * Whenever an indexed property is accessed on objects created from
8771cb0ef41Sopenharmony_ci   * this object template, the provided callback is invoked instead of
8781cb0ef41Sopenharmony_ci   * accessing the property directly on the JavaScript object.
8791cb0ef41Sopenharmony_ci   *
8801cb0ef41Sopenharmony_ci   * \param getter The callback to invoke when getting a property.
8811cb0ef41Sopenharmony_ci   * \param setter The callback to invoke when setting a property.
8821cb0ef41Sopenharmony_ci   * \param query The callback to invoke to check if an object has a property.
8831cb0ef41Sopenharmony_ci   * \param deleter The callback to invoke when deleting a property.
8841cb0ef41Sopenharmony_ci   * \param enumerator The callback to invoke to enumerate all the indexed
8851cb0ef41Sopenharmony_ci   *   properties of an object.
8861cb0ef41Sopenharmony_ci   * \param data A piece of data that will be passed to the callbacks
8871cb0ef41Sopenharmony_ci   *   whenever they are invoked.
8881cb0ef41Sopenharmony_ci   */
8891cb0ef41Sopenharmony_ci  // TODO(dcarney): deprecate
8901cb0ef41Sopenharmony_ci  void SetIndexedPropertyHandler(
8911cb0ef41Sopenharmony_ci      IndexedPropertyGetterCallback getter,
8921cb0ef41Sopenharmony_ci      IndexedPropertySetterCallback setter = nullptr,
8931cb0ef41Sopenharmony_ci      IndexedPropertyQueryCallback query = nullptr,
8941cb0ef41Sopenharmony_ci      IndexedPropertyDeleterCallback deleter = nullptr,
8951cb0ef41Sopenharmony_ci      IndexedPropertyEnumeratorCallback enumerator = nullptr,
8961cb0ef41Sopenharmony_ci      Local<Value> data = Local<Value>()) {
8971cb0ef41Sopenharmony_ci    SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query,
8981cb0ef41Sopenharmony_ci                                                   deleter, enumerator, data));
8991cb0ef41Sopenharmony_ci  }
9001cb0ef41Sopenharmony_ci
9011cb0ef41Sopenharmony_ci  /**
9021cb0ef41Sopenharmony_ci   * Sets an indexed property handler on the object template.
9031cb0ef41Sopenharmony_ci   *
9041cb0ef41Sopenharmony_ci   * Whenever an indexed property is accessed on objects created from
9051cb0ef41Sopenharmony_ci   * this object template, the provided callback is invoked instead of
9061cb0ef41Sopenharmony_ci   * accessing the property directly on the JavaScript object.
9071cb0ef41Sopenharmony_ci   *
9081cb0ef41Sopenharmony_ci   * @param configuration The IndexedPropertyHandlerConfiguration that defines
9091cb0ef41Sopenharmony_ci   * the callbacks to invoke when accessing a property.
9101cb0ef41Sopenharmony_ci   */
9111cb0ef41Sopenharmony_ci  void SetHandler(const IndexedPropertyHandlerConfiguration& configuration);
9121cb0ef41Sopenharmony_ci
9131cb0ef41Sopenharmony_ci  /**
9141cb0ef41Sopenharmony_ci   * Sets the callback to be used when calling instances created from
9151cb0ef41Sopenharmony_ci   * this template as a function.  If no callback is set, instances
9161cb0ef41Sopenharmony_ci   * behave like normal JavaScript objects that cannot be called as a
9171cb0ef41Sopenharmony_ci   * function.
9181cb0ef41Sopenharmony_ci   */
9191cb0ef41Sopenharmony_ci  void SetCallAsFunctionHandler(FunctionCallback callback,
9201cb0ef41Sopenharmony_ci                                Local<Value> data = Local<Value>());
9211cb0ef41Sopenharmony_ci
9221cb0ef41Sopenharmony_ci  /**
9231cb0ef41Sopenharmony_ci   * Mark object instances of the template as undetectable.
9241cb0ef41Sopenharmony_ci   *
9251cb0ef41Sopenharmony_ci   * In many ways, undetectable objects behave as though they are not
9261cb0ef41Sopenharmony_ci   * there.  They behave like 'undefined' in conditionals and when
9271cb0ef41Sopenharmony_ci   * printed.  However, properties can be accessed and called as on
9281cb0ef41Sopenharmony_ci   * normal objects.
9291cb0ef41Sopenharmony_ci   */
9301cb0ef41Sopenharmony_ci  void MarkAsUndetectable();
9311cb0ef41Sopenharmony_ci
9321cb0ef41Sopenharmony_ci  /**
9331cb0ef41Sopenharmony_ci   * Sets access check callback on the object template and enables access
9341cb0ef41Sopenharmony_ci   * checks.
9351cb0ef41Sopenharmony_ci   *
9361cb0ef41Sopenharmony_ci   * When accessing properties on instances of this object template,
9371cb0ef41Sopenharmony_ci   * the access check callback will be called to determine whether or
9381cb0ef41Sopenharmony_ci   * not to allow cross-context access to the properties.
9391cb0ef41Sopenharmony_ci   */
9401cb0ef41Sopenharmony_ci  void SetAccessCheckCallback(AccessCheckCallback callback,
9411cb0ef41Sopenharmony_ci                              Local<Value> data = Local<Value>());
9421cb0ef41Sopenharmony_ci
9431cb0ef41Sopenharmony_ci  /**
9441cb0ef41Sopenharmony_ci   * Like SetAccessCheckCallback but invokes an interceptor on failed access
9451cb0ef41Sopenharmony_ci   * checks instead of looking up all-can-read properties. You can only use
9461cb0ef41Sopenharmony_ci   * either this method or SetAccessCheckCallback, but not both at the same
9471cb0ef41Sopenharmony_ci   * time.
9481cb0ef41Sopenharmony_ci   */
9491cb0ef41Sopenharmony_ci  void SetAccessCheckCallbackAndHandler(
9501cb0ef41Sopenharmony_ci      AccessCheckCallback callback,
9511cb0ef41Sopenharmony_ci      const NamedPropertyHandlerConfiguration& named_handler,
9521cb0ef41Sopenharmony_ci      const IndexedPropertyHandlerConfiguration& indexed_handler,
9531cb0ef41Sopenharmony_ci      Local<Value> data = Local<Value>());
9541cb0ef41Sopenharmony_ci
9551cb0ef41Sopenharmony_ci  /**
9561cb0ef41Sopenharmony_ci   * Gets the number of internal fields for objects generated from
9571cb0ef41Sopenharmony_ci   * this template.
9581cb0ef41Sopenharmony_ci   */
9591cb0ef41Sopenharmony_ci  int InternalFieldCount() const;
9601cb0ef41Sopenharmony_ci
9611cb0ef41Sopenharmony_ci  /**
9621cb0ef41Sopenharmony_ci   * Sets the number of internal fields for objects generated from
9631cb0ef41Sopenharmony_ci   * this template.
9641cb0ef41Sopenharmony_ci   */
9651cb0ef41Sopenharmony_ci  void SetInternalFieldCount(int value);
9661cb0ef41Sopenharmony_ci
9671cb0ef41Sopenharmony_ci  /**
9681cb0ef41Sopenharmony_ci   * Returns true if the object will be an immutable prototype exotic object.
9691cb0ef41Sopenharmony_ci   */
9701cb0ef41Sopenharmony_ci  bool IsImmutableProto() const;
9711cb0ef41Sopenharmony_ci
9721cb0ef41Sopenharmony_ci  /**
9731cb0ef41Sopenharmony_ci   * Makes the ObjectTemplate for an immutable prototype exotic object, with an
9741cb0ef41Sopenharmony_ci   * immutable __proto__.
9751cb0ef41Sopenharmony_ci   */
9761cb0ef41Sopenharmony_ci  void SetImmutableProto();
9771cb0ef41Sopenharmony_ci
9781cb0ef41Sopenharmony_ci  /**
9791cb0ef41Sopenharmony_ci   * Support for TC39 "dynamic code brand checks" proposal.
9801cb0ef41Sopenharmony_ci   *
9811cb0ef41Sopenharmony_ci   * This API allows to mark (& query) objects as "code like", which causes
9821cb0ef41Sopenharmony_ci   * them to be treated like Strings in the context of eval and function
9831cb0ef41Sopenharmony_ci   * constructor.
9841cb0ef41Sopenharmony_ci   *
9851cb0ef41Sopenharmony_ci   * Reference: https://github.com/tc39/proposal-dynamic-code-brand-checks
9861cb0ef41Sopenharmony_ci   */
9871cb0ef41Sopenharmony_ci  void SetCodeLike();
9881cb0ef41Sopenharmony_ci  bool IsCodeLike() const;
9891cb0ef41Sopenharmony_ci
9901cb0ef41Sopenharmony_ci  V8_INLINE static ObjectTemplate* Cast(Data* data);
9911cb0ef41Sopenharmony_ci
9921cb0ef41Sopenharmony_ci private:
9931cb0ef41Sopenharmony_ci  ObjectTemplate();
9941cb0ef41Sopenharmony_ci  static Local<ObjectTemplate> New(internal::Isolate* isolate,
9951cb0ef41Sopenharmony_ci                                   Local<FunctionTemplate> constructor);
9961cb0ef41Sopenharmony_ci  static void CheckCast(Data* that);
9971cb0ef41Sopenharmony_ci  friend class FunctionTemplate;
9981cb0ef41Sopenharmony_ci};
9991cb0ef41Sopenharmony_ci
10001cb0ef41Sopenharmony_ci/**
10011cb0ef41Sopenharmony_ci * A Signature specifies which receiver is valid for a function.
10021cb0ef41Sopenharmony_ci *
10031cb0ef41Sopenharmony_ci * A receiver matches a given signature if the receiver (or any of its
10041cb0ef41Sopenharmony_ci * hidden prototypes) was created from the signature's FunctionTemplate, or
10051cb0ef41Sopenharmony_ci * from a FunctionTemplate that inherits directly or indirectly from the
10061cb0ef41Sopenharmony_ci * signature's FunctionTemplate.
10071cb0ef41Sopenharmony_ci */
10081cb0ef41Sopenharmony_ciclass V8_EXPORT Signature : public Data {
10091cb0ef41Sopenharmony_ci public:
10101cb0ef41Sopenharmony_ci  static Local<Signature> New(
10111cb0ef41Sopenharmony_ci      Isolate* isolate,
10121cb0ef41Sopenharmony_ci      Local<FunctionTemplate> receiver = Local<FunctionTemplate>());
10131cb0ef41Sopenharmony_ci
10141cb0ef41Sopenharmony_ci  V8_INLINE static Signature* Cast(Data* data);
10151cb0ef41Sopenharmony_ci
10161cb0ef41Sopenharmony_ci private:
10171cb0ef41Sopenharmony_ci  Signature();
10181cb0ef41Sopenharmony_ci
10191cb0ef41Sopenharmony_ci  static void CheckCast(Data* that);
10201cb0ef41Sopenharmony_ci};
10211cb0ef41Sopenharmony_ci
10221cb0ef41Sopenharmony_ci/**
10231cb0ef41Sopenharmony_ci * An AccessorSignature specifies which receivers are valid parameters
10241cb0ef41Sopenharmony_ci * to an accessor callback.
10251cb0ef41Sopenharmony_ci */
10261cb0ef41Sopenharmony_ciclass V8_EXPORT AccessorSignature : public Data {
10271cb0ef41Sopenharmony_ci public:
10281cb0ef41Sopenharmony_ci  static Local<AccessorSignature> New(
10291cb0ef41Sopenharmony_ci      Isolate* isolate,
10301cb0ef41Sopenharmony_ci      Local<FunctionTemplate> receiver = Local<FunctionTemplate>());
10311cb0ef41Sopenharmony_ci
10321cb0ef41Sopenharmony_ci  V8_INLINE static AccessorSignature* Cast(Data* data);
10331cb0ef41Sopenharmony_ci
10341cb0ef41Sopenharmony_ci private:
10351cb0ef41Sopenharmony_ci  AccessorSignature();
10361cb0ef41Sopenharmony_ci
10371cb0ef41Sopenharmony_ci  static void CheckCast(Data* that);
10381cb0ef41Sopenharmony_ci};
10391cb0ef41Sopenharmony_ci
10401cb0ef41Sopenharmony_ci// --- Implementation ---
10411cb0ef41Sopenharmony_ci
10421cb0ef41Sopenharmony_civoid Template::Set(Isolate* isolate, const char* name, Local<Data> value,
10431cb0ef41Sopenharmony_ci                   PropertyAttribute attributes) {
10441cb0ef41Sopenharmony_ci  Set(String::NewFromUtf8(isolate, name, NewStringType::kInternalized)
10451cb0ef41Sopenharmony_ci          .ToLocalChecked(),
10461cb0ef41Sopenharmony_ci      value, attributes);
10471cb0ef41Sopenharmony_ci}
10481cb0ef41Sopenharmony_ci
10491cb0ef41Sopenharmony_ciFunctionTemplate* FunctionTemplate::Cast(Data* data) {
10501cb0ef41Sopenharmony_ci#ifdef V8_ENABLE_CHECKS
10511cb0ef41Sopenharmony_ci  CheckCast(data);
10521cb0ef41Sopenharmony_ci#endif
10531cb0ef41Sopenharmony_ci  return reinterpret_cast<FunctionTemplate*>(data);
10541cb0ef41Sopenharmony_ci}
10551cb0ef41Sopenharmony_ci
10561cb0ef41Sopenharmony_ciObjectTemplate* ObjectTemplate::Cast(Data* data) {
10571cb0ef41Sopenharmony_ci#ifdef V8_ENABLE_CHECKS
10581cb0ef41Sopenharmony_ci  CheckCast(data);
10591cb0ef41Sopenharmony_ci#endif
10601cb0ef41Sopenharmony_ci  return reinterpret_cast<ObjectTemplate*>(data);
10611cb0ef41Sopenharmony_ci}
10621cb0ef41Sopenharmony_ci
10631cb0ef41Sopenharmony_ciSignature* Signature::Cast(Data* data) {
10641cb0ef41Sopenharmony_ci#ifdef V8_ENABLE_CHECKS
10651cb0ef41Sopenharmony_ci  CheckCast(data);
10661cb0ef41Sopenharmony_ci#endif
10671cb0ef41Sopenharmony_ci  return reinterpret_cast<Signature*>(data);
10681cb0ef41Sopenharmony_ci}
10691cb0ef41Sopenharmony_ci
10701cb0ef41Sopenharmony_ciAccessorSignature* AccessorSignature::Cast(Data* data) {
10711cb0ef41Sopenharmony_ci#ifdef V8_ENABLE_CHECKS
10721cb0ef41Sopenharmony_ci  CheckCast(data);
10731cb0ef41Sopenharmony_ci#endif
10741cb0ef41Sopenharmony_ci  return reinterpret_cast<AccessorSignature*>(data);
10751cb0ef41Sopenharmony_ci}
10761cb0ef41Sopenharmony_ci
10771cb0ef41Sopenharmony_ci}  // namespace v8
10781cb0ef41Sopenharmony_ci
10791cb0ef41Sopenharmony_ci#endif  // INCLUDE_V8_TEMPLATE_H_
1080