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