Where Online Learning is simpler!
The C and C++ Include Header Files
/usr/include/node/v8-template.h
$ cat -n /usr/include/node/v8-template.h 1 // Copyright 2021 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef INCLUDE_V8_TEMPLATE_H_ 6 #define INCLUDE_V8_TEMPLATE_H_ 7 8 #include
9 #include
10 11 #include "v8-data.h" // NOLINT(build/include_directory) 12 #include "v8-function-callback.h" // NOLINT(build/include_directory) 13 #include "v8-local-handle.h" // NOLINT(build/include_directory) 14 #include "v8-memory-span.h" // NOLINT(build/include_directory) 15 #include "v8-object.h" // NOLINT(build/include_directory) 16 #include "v8config.h" // NOLINT(build/include_directory) 17 18 namespace v8 { 19 20 class CFunction; 21 class FunctionTemplate; 22 class ObjectTemplate; 23 class Signature; 24 25 // --- Templates --- 26 27 #define V8_INTRINSICS_LIST(F) \ 28 F(ArrayProto_entries, array_entries_iterator) \ 29 F(ArrayProto_forEach, array_for_each_iterator) \ 30 F(ArrayProto_keys, array_keys_iterator) \ 31 F(ArrayProto_values, array_values_iterator) \ 32 F(ArrayPrototype, initial_array_prototype) \ 33 F(AsyncIteratorPrototype, initial_async_iterator_prototype) \ 34 F(ErrorPrototype, initial_error_prototype) \ 35 F(IteratorPrototype, initial_iterator_prototype) \ 36 F(MapIteratorPrototype, initial_map_iterator_prototype) \ 37 F(ObjProto_valueOf, object_value_of_function) \ 38 F(SetIteratorPrototype, initial_set_iterator_prototype) 39 40 enum Intrinsic { 41 #define V8_DECL_INTRINSIC(name, iname) k##name, 42 V8_INTRINSICS_LIST(V8_DECL_INTRINSIC) 43 #undef V8_DECL_INTRINSIC 44 }; 45 46 /** 47 * The superclass of object and function templates. 48 */ 49 class V8_EXPORT Template : public Data { 50 public: 51 /** 52 * Adds a property to each instance created by this template. 53 * 54 * The property must be defined either as a primitive value, or a template. 55 */ 56 void Set(Local
name, Local
value, 57 PropertyAttribute attributes = None); 58 void SetPrivate(Local
name, Local
value, 59 PropertyAttribute attributes = None); 60 V8_INLINE void Set(Isolate* isolate, const char* name, Local
value, 61 PropertyAttribute attributes = None); 62 63 void SetAccessorProperty( 64 Local
name, 65 Local
getter = Local
(), 66 Local
setter = Local
(), 67 PropertyAttribute attribute = None); 68 69 /** 70 * Whenever the property with the given name is accessed on objects 71 * created from this Template the getter and setter callbacks 72 * are called instead of getting and setting the property directly 73 * on the JavaScript object. 74 * 75 * \param name The name of the property for which an accessor is added. 76 * \param getter The callback to invoke when getting the property. 77 * \param setter The callback to invoke when setting the property. 78 * \param data A piece of data that will be passed to the getter and setter 79 * callbacks whenever they are invoked. 80 * \param attribute The attributes of the property for which an accessor 81 * is added. 82 */ 83 V8_DEPRECATE_SOON("Use SetNativeDataProperty without AccessControl instead") 84 void SetNativeDataProperty( 85 Local
name, AccessorGetterCallback getter, 86 AccessorSetterCallback setter, Local
data, 87 PropertyAttribute attribute, AccessControl settings, 88 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect, 89 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect); 90 V8_DEPRECATE_SOON("Use SetNativeDataProperty without AccessControl instead") 91 void SetNativeDataProperty( 92 Local
name, AccessorNameGetterCallback getter, 93 AccessorNameSetterCallback setter, Local
data, 94 PropertyAttribute attribute, AccessControl settings, 95 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect, 96 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect); 97 V8_DEPRECATE_SOON("Use SetNativeDataProperty with Local
instead") 98 void SetNativeDataProperty( 99 Local
name, AccessorGetterCallback getter, 100 AccessorSetterCallback setter = nullptr, 101 Local
data = Local
(), PropertyAttribute attribute = None, 102 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect, 103 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect); 104 void SetNativeDataProperty( 105 Local
name, AccessorNameGetterCallback getter, 106 AccessorNameSetterCallback setter = nullptr, 107 Local
data = Local
(), PropertyAttribute attribute = None, 108 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect, 109 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect); 110 111 /** 112 * Like SetNativeDataProperty, but V8 will replace the native data property 113 * with a real data property on first access. 114 */ 115 void SetLazyDataProperty( 116 Local
name, AccessorNameGetterCallback getter, 117 Local
data = Local
(), PropertyAttribute attribute = None, 118 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect, 119 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect); 120 121 /** 122 * During template instantiation, sets the value with the intrinsic property 123 * from the correct context. 124 */ 125 void SetIntrinsicDataProperty(Local
name, Intrinsic intrinsic, 126 PropertyAttribute attribute = None); 127 128 private: 129 Template(); 130 131 friend class ObjectTemplate; 132 friend class FunctionTemplate; 133 }; 134 135 /** 136 * Interceptor callbacks use this value to indicate whether the request was 137 * intercepted or not. 138 */ 139 enum class Intercepted : uint8_t { kNo = 0, kYes = 1 }; 140 141 /** 142 * Interceptor for get requests on an object. 143 * 144 * If the interceptor handles the request (i.e. the property should not be 145 * looked up beyond the interceptor) it should 146 * - (optionally) use info.GetReturnValue().Set()` to set the return value 147 * (by default the result is set to v8::Undefined), 148 * - return `Intercepted::kYes`. 149 * If the interceptor does not handle the request it must return 150 * `Intercepted::kNo` and it must not produce side effects. 151 * 152 * \param property The name of the property for which the request was 153 * intercepted. 154 * \param info Information about the intercepted request, such as 155 * isolate, receiver, return value, or whether running in `'use strict'` mode. 156 * See `PropertyCallbackInfo`. 157 * 158 * \code 159 * Intercepted GetterCallback( 160 * Local
name, const v8::PropertyCallbackInfo
& info) { 161 * if (!IsKnownProperty(info.GetIsolate(), name)) return Intercepted::kNo; 162 * info.GetReturnValue().Set(v8_num(42)); 163 * return Intercepted::kYes; 164 * } 165 * 166 * v8::Local
templ = 167 * v8::FunctionTemplate::New(isolate); 168 * templ->InstanceTemplate()->SetHandler( 169 * v8::NamedPropertyHandlerConfiguration(GetterCallback)); 170 * LocalContext env; 171 * env->Global() 172 * ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) 173 * .ToLocalChecked() 174 * ->NewInstance(env.local()) 175 * .ToLocalChecked()) 176 * .FromJust(); 177 * v8::Local
result = CompileRun("obj.a = 17; obj.a"); 178 * CHECK(v8_num(42)->Equals(env.local(), result).FromJust()); 179 * \endcode 180 * 181 * See also `ObjectTemplate::SetHandler`. 182 */ 183 using NamedPropertyGetterCallback = Intercepted (*)( 184 Local
property, const PropertyCallbackInfo
& info); 185 // This variant will be deprecated soon. 186 // 187 // Use `info.GetReturnValue().Set()` to set the return value of the 188 // intercepted get request. If the property does not exist the callback should 189 // not set the result and must not produce side effects. 190 using GenericNamedPropertyGetterCallback = 191 void (*)(Local
property, const PropertyCallbackInfo
& info); 192 193 /** 194 * Interceptor for set requests on an object. 195 * 196 * If the interceptor handles the request (i.e. the property should not be 197 * looked up beyond the interceptor) it should return `Intercepted::kYes`. 198 * If the interceptor does not handle the request it must return 199 * `Intercepted::kNo` and it must not produce side effects. 200 * 201 * \param property The name of the property for which the request was 202 * intercepted. 203 * \param value The value which the property will have if the request 204 * is not intercepted. 205 * \param info Information about the intercepted request, such as 206 * isolate, receiver, return value, or whether running in `'use strict'` mode. 207 * See `PropertyCallbackInfo`. 208 * 209 * See also `ObjectTemplate::SetHandler.` 210 */ 211 using NamedPropertySetterCallback = 212 Intercepted (*)(Local
property, Local
value, 213 const PropertyCallbackInfo
& info); 214 // This variant will be deprecated soon. 215 // 216 // Use `info.GetReturnValue()` to indicate whether the request was intercepted 217 // or not. If the setter successfully intercepts the request, i.e., if the 218 // request should not be further executed, call 219 // `info.GetReturnValue().Set(value)`. If the setter did not intercept the 220 // request, i.e., if the request should be handled as if no interceptor is 221 // present, do not not call `Set()` and do not produce side effects. 222 using GenericNamedPropertySetterCallback = 223 void (*)(Local
property, Local
value, 224 const PropertyCallbackInfo
& info); 225 226 /** 227 * Intercepts all requests that query the attributes of the 228 * property, e.g., getOwnPropertyDescriptor(), propertyIsEnumerable(), and 229 * defineProperty(). 230 * 231 * If the interceptor handles the request (i.e. the property should not be 232 * looked up beyond the interceptor) it should 233 * - use `info.GetReturnValue().Set()` to set to an Integer value encoding 234 * a `v8::PropertyAttribute` bits, 235 * - return `Intercepted::kYes`. 236 * If the interceptor does not handle the request it must return 237 * `Intercepted::kNo` and it must not produce side effects. 238 * 239 * \param property The name of the property for which the request was 240 * intercepted. 241 * \param info Information about the intercepted request, such as 242 * isolate, receiver, return value, or whether running in `'use strict'` mode. 243 * See `PropertyCallbackInfo`. 244 * 245 * \note Some functions query the property attributes internally, even though 246 * they do not return the attributes. For example, `hasOwnProperty()` can 247 * trigger this interceptor depending on the state of the object. 248 * 249 * See also `ObjectTemplate::SetHandler.` 250 */ 251 using NamedPropertyQueryCallback = Intercepted (*)( 252 Local
property, const PropertyCallbackInfo
& info); 253 // This variant will be deprecated soon. 254 // 255 // Use `info.GetReturnValue().Set(value)` to set the property attributes. The 256 // value is an integer encoding a `v8::PropertyAttribute`. If the property does 257 // not exist the callback should not set the result and must not produce side 258 // effects. 259 using GenericNamedPropertyQueryCallback = 260 void (*)(Local
property, const PropertyCallbackInfo
& info); 261 262 /** 263 * Interceptor for delete requests on an object. 264 * 265 * If the interceptor handles the request (i.e. the property should not be 266 * looked up beyond the interceptor) it should 267 * - use `info.GetReturnValue().Set()` to set to a Boolean value indicating 268 * whether the property deletion was successful or not, 269 * - return `Intercepted::kYes`. 270 * If the interceptor does not handle the request it must return 271 * `Intercepted::kNo` and it must not produce side effects. 272 * 273 * \param property The name of the property for which the request was 274 * intercepted. 275 * \param info Information about the intercepted request, such as 276 * isolate, receiver, return value, or whether running in `'use strict'` mode. 277 * See `PropertyCallbackInfo`. 278 * 279 * \note If you need to mimic the behavior of `delete`, i.e., throw in strict 280 * mode instead of returning false, use `info.ShouldThrowOnError()` to determine 281 * if you are in strict mode. 282 * 283 * See also `ObjectTemplate::SetHandler.` 284 */ 285 using NamedPropertyDeleterCallback = Intercepted (*)( 286 Local
property, const PropertyCallbackInfo
& info); 287 // This variant will be deprecated soon. 288 // 289 // Use `info.GetReturnValue()` to indicate whether the request was intercepted 290 // or not. If the deleter successfully intercepts the request, i.e., if the 291 // request should not be further executed, call 292 // `info.GetReturnValue().Set(value)` with a boolean `value`. The `value` is 293 // used as the return value of `delete`. If the deleter does not intercept the 294 // request then it should not set the result and must not produce side effects. 295 using GenericNamedPropertyDeleterCallback = 296 void (*)(Local
property, const PropertyCallbackInfo
& info); 297 298 /** 299 * Returns an array containing the names of the properties the named 300 * property getter intercepts. 301 * 302 * Note: The values in the array must be of type v8::Name. 303 */ 304 using NamedPropertyEnumeratorCallback = 305 void (*)(const PropertyCallbackInfo
& info); 306 // This variant will be deprecated soon. 307 // This is just a renaming of the typedef. 308 using GenericNamedPropertyEnumeratorCallback = NamedPropertyEnumeratorCallback; 309 310 /** 311 * Interceptor for defineProperty requests on an object. 312 * 313 * If the interceptor handles the request (i.e. the property should not be 314 * looked up beyond the interceptor) it should return `Intercepted::kYes`. 315 * If the interceptor does not handle the request it must return 316 * `Intercepted::kNo` and it must not produce side effects. 317 * 318 * \param property The name of the property for which the request was 319 * intercepted. 320 * \param desc The property descriptor which is used to define the 321 * property if the request is not intercepted. 322 * \param info Information about the intercepted request, such as 323 * isolate, receiver, return value, or whether running in `'use strict'` mode. 324 * See `PropertyCallbackInfo`. 325 * 326 * See also `ObjectTemplate::SetHandler`. 327 */ 328 using NamedPropertyDefinerCallback = 329 Intercepted (*)(Local
property, const PropertyDescriptor& desc, 330 const PropertyCallbackInfo
& info); 331 // This variant will be deprecated soon. 332 // 333 // Use `info.GetReturnValue()` to indicate whether the request was intercepted 334 // or not. If the definer successfully intercepts the request, i.e., if the 335 // request should not be further executed, call 336 // `info.GetReturnValue().Set(value)`. If the definer did not intercept the 337 // request, i.e., if the request should be handled as if no interceptor is 338 // present, do not not call `Set()` and do not produce side effects. 339 using GenericNamedPropertyDefinerCallback = 340 void (*)(Local
property, const PropertyDescriptor& desc, 341 const PropertyCallbackInfo
& info); 342 343 /** 344 * Interceptor for getOwnPropertyDescriptor requests on an object. 345 * 346 * If the interceptor handles the request (i.e. the property should not be 347 * looked up beyond the interceptor) it should 348 * - use `info.GetReturnValue().Set()` to set the return value which must be 349 * object that can be converted to a PropertyDescriptor (for example, 350 * a value returned by `v8::Object::getOwnPropertyDescriptor`), 351 * - return `Intercepted::kYes`. 352 * If the interceptor does not handle the request it must return 353 * `Intercepted::kNo` and it must not produce side effects. 354 * 355 * \param property The name of the property for which the request was 356 * intercepted. 357 * \info Information about the intercepted request, such as 358 * isolate, receiver, return value, or whether running in `'use strict'` mode. 359 * See `PropertyCallbackInfo`. 360 * 361 * \note If GetOwnPropertyDescriptor is intercepted, it will 362 * always return true, i.e., indicate that the property was found. 363 * 364 * See also `ObjectTemplate::SetHandler`. 365 */ 366 using NamedPropertyDescriptorCallback = Intercepted (*)( 367 Local
property, const PropertyCallbackInfo
& info); 368 // This variant will be deprecated soon. 369 // 370 // Use `info.GetReturnValue().Set()` to set the return value of the 371 // intercepted request. The return value must be an object that 372 // can be converted to a PropertyDescriptor, e.g., a `v8::Value` returned from 373 // `v8::Object::getOwnPropertyDescriptor`. 374 using GenericNamedPropertyDescriptorCallback = 375 void (*)(Local
property, const PropertyCallbackInfo
& info); 376 377 // TODO(ishell): Rename IndexedPropertyXxxCallbackV2 back to 378 // IndexedPropertyXxxCallback once the old IndexedPropertyXxxCallback is 379 // removed. 380 381 /** 382 * See `v8::GenericNamedPropertyGetterCallback`. 383 */ 384 using IndexedPropertyGetterCallbackV2 = 385 Intercepted (*)(uint32_t index, const PropertyCallbackInfo
& info); 386 // This variant will be deprecated soon. 387 using IndexedPropertyGetterCallback = 388 void (*)(uint32_t index, const PropertyCallbackInfo
& info); 389 390 /** 391 * See `v8::GenericNamedPropertySetterCallback`. 392 */ 393 using IndexedPropertySetterCallbackV2 = Intercepted (*)( 394 uint32_t index, Local
value, const PropertyCallbackInfo
& info); 395 // This variant will be deprecated soon. 396 using IndexedPropertySetterCallback = 397 void (*)(uint32_t index, Local
value, 398 const PropertyCallbackInfo
& info); 399 400 /** 401 * See `v8::GenericNamedPropertyQueryCallback`. 402 */ 403 using IndexedPropertyQueryCallbackV2 = 404 Intercepted (*)(uint32_t index, const PropertyCallbackInfo
& info); 405 // This variant will be deprecated soon. 406 using IndexedPropertyQueryCallback = 407 void (*)(uint32_t index, const PropertyCallbackInfo
& info); 408 409 /** 410 * See `v8::GenericNamedPropertyDeleterCallback`. 411 */ 412 using IndexedPropertyDeleterCallbackV2 = 413 Intercepted (*)(uint32_t index, const PropertyCallbackInfo
& info); 414 // This variant will be deprecated soon. 415 using IndexedPropertyDeleterCallback = 416 void (*)(uint32_t index, const PropertyCallbackInfo
& info); 417 418 /** 419 * Returns an array containing the indices of the properties the indexed 420 * property getter intercepts. 421 * 422 * Note: The values in the array must be uint32_t. 423 */ 424 using IndexedPropertyEnumeratorCallback = 425 void (*)(const PropertyCallbackInfo
& info); 426 427 /** 428 * See `v8::GenericNamedPropertyDefinerCallback`. 429 */ 430 using IndexedPropertyDefinerCallbackV2 = 431 Intercepted (*)(uint32_t index, const PropertyDescriptor& desc, 432 const PropertyCallbackInfo
& info); 433 // This variant will be deprecated soon. 434 using IndexedPropertyDefinerCallback = 435 void (*)(uint32_t index, const PropertyDescriptor& desc, 436 const PropertyCallbackInfo
& info); 437 438 /** 439 * See `v8::GenericNamedPropertyDescriptorCallback`. 440 */ 441 using IndexedPropertyDescriptorCallbackV2 = 442 Intercepted (*)(uint32_t index, const PropertyCallbackInfo
& info); 443 // This variant will be deprecated soon. 444 using IndexedPropertyDescriptorCallback = 445 void (*)(uint32_t index, const PropertyCallbackInfo
& info); 446 447 /** 448 * Returns true if the given context should be allowed to access the given 449 * object. 450 */ 451 using AccessCheckCallback = bool (*)(Local
accessing_context, 452 Local
accessed_object, 453 Local
data); 454 455 enum class ConstructorBehavior { kThrow, kAllow }; 456 457 /** 458 * A FunctionTemplate is used to create functions at runtime. There 459 * can only be one function created from a FunctionTemplate in a 460 * context. The lifetime of the created function is equal to the 461 * lifetime of the context. So in case the embedder needs to create 462 * temporary functions that can be collected using Scripts is 463 * preferred. 464 * 465 * Any modification of a FunctionTemplate after first instantiation will trigger 466 * a crash. 467 * 468 * A FunctionTemplate can have properties, these properties are added to the 469 * function object when it is created. 470 * 471 * A FunctionTemplate has a corresponding instance template which is 472 * used to create object instances when the function is used as a 473 * constructor. Properties added to the instance template are added to 474 * each object instance. 475 * 476 * A FunctionTemplate can have a prototype template. The prototype template 477 * is used to create the prototype object of the function. 478 * 479 * The following example shows how to use a FunctionTemplate: 480 * 481 * \code 482 * v8::Local
t = v8::FunctionTemplate::New(isolate); 483 * t->Set(isolate, "func_property", v8::Number::New(isolate, 1)); 484 * 485 * v8::Local
proto_t = t->PrototypeTemplate(); 486 * proto_t->Set(isolate, 487 * "proto_method", 488 * v8::FunctionTemplate::New(isolate, InvokeCallback)); 489 * proto_t->Set(isolate, "proto_const", v8::Number::New(isolate, 2)); 490 * 491 * v8::Local
instance_t = t->InstanceTemplate(); 492 * instance_t->SetAccessor( 493 String::NewFromUtf8Literal(isolate, "instance_accessor"), 494 * InstanceAccessorCallback); 495 * instance_t->SetHandler( 496 * NamedPropertyHandlerConfiguration(PropertyHandlerCallback)); 497 * instance_t->Set(String::NewFromUtf8Literal(isolate, "instance_property"), 498 * Number::New(isolate, 3)); 499 * 500 * v8::Local
function = t->GetFunction(); 501 * v8::Local
instance = function->NewInstance(); 502 * \endcode 503 * 504 * Let's use "function" as the JS variable name of the function object 505 * and "instance" for the instance object created above. The function 506 * and the instance will have the following properties: 507 * 508 * \code 509 * func_property in function == true; 510 * function.func_property == 1; 511 * 512 * function.prototype.proto_method() invokes 'InvokeCallback' 513 * function.prototype.proto_const == 2; 514 * 515 * instance instanceof function == true; 516 * instance.instance_accessor calls 'InstanceAccessorCallback' 517 * instance.instance_property == 3; 518 * \endcode 519 * 520 * A FunctionTemplate can inherit from another one by calling the 521 * FunctionTemplate::Inherit method. The following graph illustrates 522 * the semantics of inheritance: 523 * 524 * \code 525 * FunctionTemplate Parent -> Parent() . prototype -> { } 526 * ^ ^ 527 * | Inherit(Parent) | .__proto__ 528 * | | 529 * FunctionTemplate Child -> Child() . prototype -> { } 530 * \endcode 531 * 532 * A FunctionTemplate 'Child' inherits from 'Parent', the prototype 533 * object of the Child() function has __proto__ pointing to the 534 * Parent() function's prototype object. An instance of the Child 535 * function has all properties on Parent's instance templates. 536 * 537 * Let Parent be the FunctionTemplate initialized in the previous 538 * section and create a Child FunctionTemplate by: 539 * 540 * \code 541 * Local
parent = t; 542 * Local
child = FunctionTemplate::New(); 543 * child->Inherit(parent); 544 * 545 * Local
child_function = child->GetFunction(); 546 * Local
child_instance = child_function->NewInstance(); 547 * \endcode 548 * 549 * The Child function and Child instance will have the following 550 * properties: 551 * 552 * \code 553 * child_func.prototype.__proto__ == function.prototype; 554 * child_instance.instance_accessor calls 'InstanceAccessorCallback' 555 * child_instance.instance_property == 3; 556 * \endcode 557 * 558 * The additional 'c_function' parameter refers to a fast API call, which 559 * must not trigger GC or JavaScript execution, or call into V8 in other 560 * ways. For more information how to define them, see 561 * include/v8-fast-api-calls.h. Please note that this feature is still 562 * experimental. 563 */ 564 class V8_EXPORT FunctionTemplate : public Template { 565 public: 566 /** Creates a function template.*/ 567 static Local
New( 568 Isolate* isolate, FunctionCallback callback = nullptr, 569 Local
data = Local
(), 570 Local
signature = Local
(), int length = 0, 571 ConstructorBehavior behavior = ConstructorBehavior::kAllow, 572 SideEffectType side_effect_type = SideEffectType::kHasSideEffect, 573 const CFunction* c_function = nullptr, uint16_t instance_type = 0, 574 uint16_t allowed_receiver_instance_type_range_start = 0, 575 uint16_t allowed_receiver_instance_type_range_end = 0); 576 577 /** Creates a function template for multiple overloaded fast API calls.*/ 578 static Local
NewWithCFunctionOverloads( 579 Isolate* isolate, FunctionCallback callback = nullptr, 580 Local
data = Local
(), 581 Local
signature = Local
(), int length = 0, 582 ConstructorBehavior behavior = ConstructorBehavior::kAllow, 583 SideEffectType side_effect_type = SideEffectType::kHasSideEffect, 584 const MemorySpan
& c_function_overloads = {}); 585 586 /** 587 * Creates a function template backed/cached by a private property. 588 */ 589 static Local
NewWithCache( 590 Isolate* isolate, FunctionCallback callback, 591 Local
cache_property, Local
data = Local
(), 592 Local
signature = Local
(), int length = 0, 593 SideEffectType side_effect_type = SideEffectType::kHasSideEffect); 594 595 /** Returns the unique function instance in the current execution context.*/ 596 V8_WARN_UNUSED_RESULT MaybeLocal
GetFunction( 597 Local
context); 598 599 /** 600 * Similar to Context::NewRemoteContext, this creates an instance that 601 * isn't backed by an actual object. 602 * 603 * The InstanceTemplate of this FunctionTemplate must have access checks with 604 * handlers installed. 605 */ 606 V8_WARN_UNUSED_RESULT MaybeLocal
NewRemoteInstance(); 607 608 /** 609 * Set the call-handler callback for a FunctionTemplate. This 610 * callback is called whenever the function created from this 611 * FunctionTemplate is called. The 'c_function' represents a fast 612 * API call, see the comment above the class declaration. 613 */ 614 void SetCallHandler( 615 FunctionCallback callback, Local
data = Local
(), 616 SideEffectType side_effect_type = SideEffectType::kHasSideEffect, 617 const MemorySpan
& c_function_overloads = {}); 618 619 /** Set the predefined length property for the FunctionTemplate. */ 620 void SetLength(int length); 621 622 /** Get the InstanceTemplate. */ 623 Local
InstanceTemplate(); 624 625 /** 626 * Causes the function template to inherit from a parent function template. 627 * This means the function's prototype.__proto__ is set to the parent 628 * function's prototype. 629 **/ 630 void Inherit(Local
parent); 631 632 /** 633 * A PrototypeTemplate is the template used to create the prototype object 634 * of the function created by this template. 635 */ 636 Local
PrototypeTemplate(); 637 638 /** 639 * A PrototypeProviderTemplate is another function template whose prototype 640 * property is used for this template. This is mutually exclusive with setting 641 * a prototype template indirectly by calling PrototypeTemplate() or using 642 * Inherit(). 643 **/ 644 void SetPrototypeProviderTemplate(Local
prototype_provider); 645 646 /** 647 * Set the class name of the FunctionTemplate. This is used for 648 * printing objects created with the function created from the 649 * FunctionTemplate as its constructor. 650 */ 651 void SetClassName(Local
name); 652 653 /** 654 * When set to true, no access check will be performed on the receiver of a 655 * function call. Currently defaults to true, but this is subject to change. 656 */ 657 void SetAcceptAnyReceiver(bool value); 658 659 /** 660 * Sets the ReadOnly flag in the attributes of the 'prototype' property 661 * of functions created from this FunctionTemplate to true. 662 */ 663 void ReadOnlyPrototype(); 664 665 /** 666 * Removes the prototype property from functions created from this 667 * FunctionTemplate. 668 */ 669 void RemovePrototype(); 670 671 /** 672 * Returns true if the given object is an instance of this function 673 * template. 674 */ 675 bool HasInstance(Local
object); 676 677 /** 678 * Returns true if the given value is an API object that was constructed by an 679 * instance of this function template (without checking for inheriting 680 * function templates). 681 * 682 * This is an experimental feature and may still change significantly. 683 */ 684 bool IsLeafTemplateForApiObject(v8::Local
value) const; 685 686 V8_INLINE static FunctionTemplate* Cast(Data* data); 687 688 private: 689 FunctionTemplate(); 690 691 static void CheckCast(Data* that); 692 friend class Context; 693 friend class ObjectTemplate; 694 }; 695 696 /** 697 * Configuration flags for v8::NamedPropertyHandlerConfiguration or 698 * v8::IndexedPropertyHandlerConfiguration. 699 */ 700 enum class PropertyHandlerFlags { 701 /** 702 * None. 703 */ 704 kNone = 0, 705 706 /** 707 * Will not call into interceptor for properties on the receiver or prototype 708 * chain, i.e., only call into interceptor for properties that do not exist. 709 * Currently only valid for named interceptors. 710 */ 711 kNonMasking = 1, 712 713 /** 714 * Will not call into interceptor for symbol lookup. Only meaningful for 715 * named interceptors. 716 */ 717 kOnlyInterceptStrings = 1 << 1, 718 719 /** 720 * The getter, query, enumerator callbacks do not produce side effects. 721 */ 722 kHasNoSideEffect = 1 << 2, 723 724 /** 725 * This flag is used to distinguish which callbacks were provided - 726 * GenericNamedPropertyXXXCallback (old signature) or 727 * NamedPropertyXXXCallback (new signature). 728 * DO NOT use this flag, it'll be removed once embedders migrate to new 729 * callbacks signatures. 730 */ 731 kInternalNewCallbacksSignatures = 1 << 10, 732 }; 733 734 struct NamedPropertyHandlerConfiguration { 735 private: 736 static constexpr PropertyHandlerFlags WithNewSignatureFlag( 737 PropertyHandlerFlags flags) { 738 return static_cast
( 739 static_cast
(flags) | 740 static_cast
( 741 PropertyHandlerFlags::kInternalNewCallbacksSignatures)); 742 } 743 744 public: 745 NamedPropertyHandlerConfiguration( 746 NamedPropertyGetterCallback getter, // 747 NamedPropertySetterCallback setter, // 748 NamedPropertyQueryCallback query, // 749 NamedPropertyDeleterCallback deleter, // 750 NamedPropertyEnumeratorCallback enumerator, // 751 NamedPropertyDefinerCallback definer, // 752 NamedPropertyDescriptorCallback descriptor, // 753 Local
data = Local
(), 754 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) 755 : getter(reinterpret_cast
(getter)), 756 setter(reinterpret_cast
(setter)), 757 query(reinterpret_cast
(query)), 758 deleter(reinterpret_cast
(deleter)), 759 enumerator(enumerator), 760 definer(reinterpret_cast
(definer)), 761 descriptor(reinterpret_cast
(descriptor)), 762 data(data), 763 flags(WithNewSignatureFlag(flags)) {} 764 765 // This variant will be deprecated soon. 766 NamedPropertyHandlerConfiguration( 767 GenericNamedPropertyGetterCallback getter, 768 GenericNamedPropertySetterCallback setter, 769 GenericNamedPropertyQueryCallback query, 770 GenericNamedPropertyDeleterCallback deleter, 771 GenericNamedPropertyEnumeratorCallback enumerator, 772 GenericNamedPropertyDefinerCallback definer, 773 GenericNamedPropertyDescriptorCallback descriptor, 774 Local
data = Local
(), 775 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) 776 : getter(reinterpret_cast
(getter)), 777 setter(reinterpret_cast
(setter)), 778 query(reinterpret_cast
(query)), 779 deleter(reinterpret_cast
(deleter)), 780 enumerator(enumerator), 781 definer(reinterpret_cast
(definer)), 782 descriptor(reinterpret_cast
(descriptor)), 783 data(data), 784 flags(flags) {} 785 786 explicit NamedPropertyHandlerConfiguration( 787 NamedPropertyGetterCallback getter, 788 NamedPropertySetterCallback setter = nullptr, 789 NamedPropertyQueryCallback query = nullptr, 790 NamedPropertyDeleterCallback deleter = nullptr, 791 NamedPropertyEnumeratorCallback enumerator = nullptr, 792 Local
data = Local
(), 793 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) 794 : getter(reinterpret_cast
(getter)), 795 setter(reinterpret_cast
(setter)), 796 query(reinterpret_cast
(query)), 797 deleter(reinterpret_cast
(deleter)), 798 enumerator(enumerator), 799 definer(nullptr), 800 descriptor(nullptr), 801 data(data), 802 flags(WithNewSignatureFlag(flags)) {} 803 804 // This variant will be deprecated soon. 805 explicit NamedPropertyHandlerConfiguration( 806 GenericNamedPropertyGetterCallback getter, 807 GenericNamedPropertySetterCallback setter = nullptr, 808 GenericNamedPropertyQueryCallback query = nullptr, 809 GenericNamedPropertyDeleterCallback deleter = nullptr, 810 GenericNamedPropertyEnumeratorCallback enumerator = nullptr, 811 Local
data = Local
(), 812 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) 813 : getter(reinterpret_cast
(getter)), 814 setter(reinterpret_cast
(setter)), 815 query(reinterpret_cast
(query)), 816 deleter(reinterpret_cast
(deleter)), 817 enumerator(enumerator), 818 definer(nullptr), 819 descriptor(nullptr), 820 data(data), 821 flags(flags) {} 822 823 NamedPropertyHandlerConfiguration( 824 NamedPropertyGetterCallback getter, // 825 NamedPropertySetterCallback setter, // 826 NamedPropertyDescriptorCallback descriptor, // 827 NamedPropertyDeleterCallback deleter, // 828 NamedPropertyEnumeratorCallback enumerator, // 829 NamedPropertyDefinerCallback definer, // 830 Local
data = Local
(), 831 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) 832 : getter(reinterpret_cast
(getter)), 833 setter(reinterpret_cast
(setter)), 834 query(nullptr), 835 deleter(reinterpret_cast
(deleter)), 836 enumerator(enumerator), 837 definer(reinterpret_cast
(definer)), 838 descriptor(reinterpret_cast
(descriptor)), 839 data(data), 840 flags(WithNewSignatureFlag(flags)) {} 841 842 // This variant will be deprecated soon. 843 NamedPropertyHandlerConfiguration( 844 GenericNamedPropertyGetterCallback getter, 845 GenericNamedPropertySetterCallback setter, 846 GenericNamedPropertyDescriptorCallback descriptor, 847 GenericNamedPropertyDeleterCallback deleter, 848 GenericNamedPropertyEnumeratorCallback enumerator, 849 GenericNamedPropertyDefinerCallback definer, 850 Local
data = Local
(), 851 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) 852 : getter(reinterpret_cast
(getter)), 853 setter(reinterpret_cast
(setter)), 854 query(nullptr), 855 deleter(reinterpret_cast
(deleter)), 856 enumerator(enumerator), 857 definer(reinterpret_cast
(definer)), 858 descriptor(reinterpret_cast
(descriptor)), 859 data(data), 860 flags(flags) {} 861 862 void* getter; // [Generic]NamedPropertyGetterCallback 863 void* setter; // [Generic]NamedPropertySetterCallback 864 void* query; // [Generic]NamedPropertyQueryCallback 865 void* deleter; // [Generic]NamedPropertyDeleterCallback 866 NamedPropertyEnumeratorCallback enumerator; 867 void* definer; // [Generic]NamedPropertyDefinerCallback 868 void* descriptor; // [Generic]NamedPropertyDescriptorCallback 869 Local
data; 870 PropertyHandlerFlags flags; 871 }; 872 873 struct IndexedPropertyHandlerConfiguration { 874 private: 875 static constexpr PropertyHandlerFlags WithNewSignatureFlag( 876 PropertyHandlerFlags flags) { 877 return static_cast
( 878 static_cast
(flags) | 879 static_cast
( 880 PropertyHandlerFlags::kInternalNewCallbacksSignatures)); 881 } 882 883 public: 884 IndexedPropertyHandlerConfiguration( 885 IndexedPropertyGetterCallbackV2 getter, // 886 IndexedPropertySetterCallbackV2 setter, // 887 IndexedPropertyQueryCallbackV2 query, // 888 IndexedPropertyDeleterCallbackV2 deleter, // 889 IndexedPropertyEnumeratorCallback enumerator, // 890 IndexedPropertyDefinerCallbackV2 definer, // 891 IndexedPropertyDescriptorCallbackV2 descriptor, // 892 Local
data = Local
(), 893 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) 894 : getter(reinterpret_cast
(getter)), 895 setter(reinterpret_cast
(setter)), 896 query(reinterpret_cast
(query)), 897 deleter(reinterpret_cast
(deleter)), 898 enumerator(enumerator), 899 definer(reinterpret_cast
(definer)), 900 descriptor(reinterpret_cast
(descriptor)), 901 data(data), 902 flags(WithNewSignatureFlag(flags)) {} 903 904 // This variant will be deprecated soon. 905 IndexedPropertyHandlerConfiguration( 906 IndexedPropertyGetterCallback getter, // 907 IndexedPropertySetterCallback setter, // 908 IndexedPropertyQueryCallback query, // 909 IndexedPropertyDeleterCallback deleter, // 910 IndexedPropertyEnumeratorCallback enumerator, // 911 IndexedPropertyDefinerCallback definer, // 912 IndexedPropertyDescriptorCallback descriptor, // 913 Local
data = Local
(), 914 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) 915 : getter(reinterpret_cast
(getter)), 916 setter(reinterpret_cast
(setter)), 917 query(reinterpret_cast
(query)), 918 deleter(reinterpret_cast
(deleter)), 919 enumerator(enumerator), 920 definer(reinterpret_cast
(definer)), 921 descriptor(reinterpret_cast
(descriptor)), 922 data(data), 923 flags(flags) {} 924 925 explicit IndexedPropertyHandlerConfiguration( 926 IndexedPropertyGetterCallbackV2 getter = nullptr, 927 IndexedPropertySetterCallbackV2 setter = nullptr, 928 IndexedPropertyQueryCallbackV2 query = nullptr, 929 IndexedPropertyDeleterCallbackV2 deleter = nullptr, 930 IndexedPropertyEnumeratorCallback enumerator = nullptr, 931 Local
data = Local
(), 932 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) 933 : getter(reinterpret_cast
(getter)), 934 setter(reinterpret_cast
(setter)), 935 query(reinterpret_cast
(query)), 936 deleter(reinterpret_cast
(deleter)), 937 enumerator(enumerator), 938 definer(nullptr), 939 descriptor(nullptr), 940 data(data), 941 flags(WithNewSignatureFlag(flags)) {} 942 943 // This variant will be deprecated soon. 944 explicit IndexedPropertyHandlerConfiguration( 945 IndexedPropertyGetterCallback getter, 946 IndexedPropertySetterCallback setter = nullptr, 947 IndexedPropertyQueryCallback query = nullptr, 948 IndexedPropertyDeleterCallback deleter = nullptr, 949 IndexedPropertyEnumeratorCallback enumerator = nullptr, 950 Local
data = Local
(), 951 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) 952 : getter(reinterpret_cast
(getter)), 953 setter(reinterpret_cast
(setter)), 954 query(reinterpret_cast
(query)), 955 deleter(reinterpret_cast
(deleter)), 956 enumerator(enumerator), 957 definer(nullptr), 958 descriptor(nullptr), 959 data(data), 960 flags(flags) {} 961 962 IndexedPropertyHandlerConfiguration( 963 IndexedPropertyGetterCallbackV2 getter, 964 IndexedPropertySetterCallbackV2 setter, 965 IndexedPropertyDescriptorCallbackV2 descriptor, 966 IndexedPropertyDeleterCallbackV2 deleter, 967 IndexedPropertyEnumeratorCallback enumerator, 968 IndexedPropertyDefinerCallbackV2 definer, 969 Local
data = Local
(), 970 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) 971 : getter(reinterpret_cast
(getter)), 972 setter(reinterpret_cast
(setter)), 973 query(nullptr), 974 deleter(reinterpret_cast
(deleter)), 975 enumerator(enumerator), 976 definer(reinterpret_cast
(definer)), 977 descriptor(reinterpret_cast
(descriptor)), 978 data(data), 979 flags(WithNewSignatureFlag(flags)) {} 980 981 // This variant will be deprecated soon. 982 IndexedPropertyHandlerConfiguration( 983 IndexedPropertyGetterCallback getter, 984 IndexedPropertySetterCallback setter, 985 IndexedPropertyDescriptorCallback descriptor, 986 IndexedPropertyDeleterCallback deleter, 987 IndexedPropertyEnumeratorCallback enumerator, 988 IndexedPropertyDefinerCallback definer, 989 Local
data = Local
(), 990 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) 991 : getter(reinterpret_cast
(getter)), 992 setter(reinterpret_cast
(setter)), 993 query(nullptr), 994 deleter(reinterpret_cast
(deleter)), 995 enumerator(enumerator), 996 definer(reinterpret_cast
(definer)), 997 descriptor(reinterpret_cast
(descriptor)), 998 data(data), 999 flags(flags) {} 1000 1001 void* getter; // IndexedPropertyGetterCallback[V2] 1002 void* setter; // IndexedPropertySetterCallback[V2] 1003 void* query; // IndexedPropertyQueryCallback[V2] 1004 void* deleter; // IndexedPropertyDeleterCallback[V2] 1005 IndexedPropertyEnumeratorCallback enumerator; 1006 void* definer; // IndexedPropertyDefinerCallback[V2] 1007 void* descriptor; // IndexedPropertyDescriptorCallback[V2] 1008 Local
data; 1009 PropertyHandlerFlags flags; 1010 }; 1011 1012 /** 1013 * An ObjectTemplate is used to create objects at runtime. 1014 * 1015 * Properties added to an ObjectTemplate are added to each object 1016 * created from the ObjectTemplate. 1017 */ 1018 class V8_EXPORT ObjectTemplate : public Template { 1019 public: 1020 /** Creates an ObjectTemplate. */ 1021 static Local
New( 1022 Isolate* isolate, 1023 Local
constructor = Local
()); 1024 1025 /** 1026 * Creates a new instance of this template. 1027 * 1028 * \param context The context in which the instance is created. 1029 */ 1030 V8_WARN_UNUSED_RESULT MaybeLocal
NewInstance(Local
context); 1031 1032 /** 1033 * Sets an accessor on the object template. 1034 * 1035 * Whenever the property with the given name is accessed on objects 1036 * created from this ObjectTemplate the getter and setter callbacks 1037 * are called instead of getting and setting the property directly 1038 * on the JavaScript object. 1039 * 1040 * \param name The name of the property for which an accessor is added. 1041 * \param getter The callback to invoke when getting the property. 1042 * \param setter The callback to invoke when setting the property. 1043 * \param data A piece of data that will be passed to the getter and setter 1044 * callbacks whenever they are invoked. 1045 * \param attribute The attributes of the property for which an accessor 1046 * is added. 1047 */ 1048 V8_DEPRECATE_SOON("Use SetAccessor with Local
instead") 1049 void SetAccessor( 1050 Local
name, AccessorGetterCallback getter, 1051 AccessorSetterCallback setter = nullptr, 1052 Local
data = Local
(), PropertyAttribute attribute = None, 1053 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect, 1054 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect); 1055 void SetAccessor( 1056 Local
name, AccessorNameGetterCallback getter, 1057 AccessorNameSetterCallback setter = nullptr, 1058 Local
data = Local
(), PropertyAttribute attribute = None, 1059 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect, 1060 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect); 1061 1062 /** 1063 * Sets a named property handler on the object template. 1064 * 1065 * Whenever a property whose name is a string or a symbol is accessed on 1066 * objects created from this object template, the provided callback is 1067 * invoked instead of accessing the property directly on the JavaScript 1068 * object. 1069 * 1070 * @param configuration The NamedPropertyHandlerConfiguration that defines the 1071 * callbacks to invoke when accessing a property. 1072 */ 1073 void SetHandler(const NamedPropertyHandlerConfiguration& configuration); 1074 1075 /** 1076 * Sets an indexed property handler on the object template. 1077 * 1078 * Whenever an indexed property is accessed on objects created from 1079 * this object template, the provided callback is invoked instead of 1080 * accessing the property directly on the JavaScript object. 1081 * 1082 * \param getter The callback to invoke when getting a property. 1083 * \param setter The callback to invoke when setting a property. 1084 * \param query The callback to invoke to check if an object has a property. 1085 * \param deleter The callback to invoke when deleting a property. 1086 * \param enumerator The callback to invoke to enumerate all the indexed 1087 * properties of an object. 1088 * \param data A piece of data that will be passed to the callbacks 1089 * whenever they are invoked. 1090 */ 1091 V8_DEPRECATE_SOON("Use SetHandler instead") 1092 void SetIndexedPropertyHandler( 1093 IndexedPropertyGetterCallback getter, 1094 IndexedPropertySetterCallback setter = nullptr, 1095 IndexedPropertyQueryCallback query = nullptr, 1096 IndexedPropertyDeleterCallback deleter = nullptr, 1097 IndexedPropertyEnumeratorCallback enumerator = nullptr, 1098 Local
data = Local
()) { 1099 SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query, 1100 deleter, enumerator, data)); 1101 } 1102 1103 /** 1104 * Sets an indexed property handler on the object template. 1105 * 1106 * Whenever an indexed property is accessed on objects created from 1107 * this object template, the provided callback is invoked instead of 1108 * accessing the property directly on the JavaScript object. 1109 * 1110 * @param configuration The IndexedPropertyHandlerConfiguration that defines 1111 * the callbacks to invoke when accessing a property. 1112 */ 1113 void SetHandler(const IndexedPropertyHandlerConfiguration& configuration); 1114 1115 /** 1116 * Sets the callback to be used when calling instances created from 1117 * this template as a function. If no callback is set, instances 1118 * behave like normal JavaScript objects that cannot be called as a 1119 * function. 1120 */ 1121 void SetCallAsFunctionHandler(FunctionCallback callback, 1122 Local
data = Local
()); 1123 1124 /** 1125 * Mark object instances of the template as undetectable. 1126 * 1127 * In many ways, undetectable objects behave as though they are not 1128 * there. They behave like 'undefined' in conditionals and when 1129 * printed. However, properties can be accessed and called as on 1130 * normal objects. 1131 */ 1132 void MarkAsUndetectable(); 1133 1134 /** 1135 * Sets access check callback on the object template and enables access 1136 * checks. 1137 * 1138 * When accessing properties on instances of this object template, 1139 * the access check callback will be called to determine whether or 1140 * not to allow cross-context access to the properties. 1141 */ 1142 void SetAccessCheckCallback(AccessCheckCallback callback, 1143 Local
data = Local
()); 1144 1145 /** 1146 * Like SetAccessCheckCallback but invokes an interceptor on failed access 1147 * checks instead of looking up all-can-read properties. You can only use 1148 * either this method or SetAccessCheckCallback, but not both at the same 1149 * time. 1150 */ 1151 void SetAccessCheckCallbackAndHandler( 1152 AccessCheckCallback callback, 1153 const NamedPropertyHandlerConfiguration& named_handler, 1154 const IndexedPropertyHandlerConfiguration& indexed_handler, 1155 Local
data = Local
()); 1156 1157 /** 1158 * Gets the number of internal fields for objects generated from 1159 * this template. 1160 */ 1161 int InternalFieldCount() const; 1162 1163 /** 1164 * Sets the number of internal fields for objects generated from 1165 * this template. 1166 */ 1167 void SetInternalFieldCount(int value); 1168 1169 /** 1170 * Returns true if the object will be an immutable prototype exotic object. 1171 */ 1172 bool IsImmutableProto() const; 1173 1174 /** 1175 * Makes the ObjectTemplate for an immutable prototype exotic object, with an 1176 * immutable __proto__. 1177 */ 1178 void SetImmutableProto(); 1179 1180 /** 1181 * Support for TC39 "dynamic code brand checks" proposal. 1182 * 1183 * This API allows to mark (& query) objects as "code like", which causes 1184 * them to be treated like Strings in the context of eval and function 1185 * constructor. 1186 * 1187 * Reference: https://github.com/tc39/proposal-dynamic-code-brand-checks 1188 */ 1189 void SetCodeLike(); 1190 bool IsCodeLike() const; 1191 1192 V8_INLINE static ObjectTemplate* Cast(Data* data); 1193 1194 private: 1195 ObjectTemplate(); 1196 1197 static void CheckCast(Data* that); 1198 friend class FunctionTemplate; 1199 }; 1200 1201 /** 1202 * A template to create dictionary objects at runtime. 1203 */ 1204 class V8_EXPORT DictionaryTemplate final { 1205 public: 1206 /** Creates a new template. Also declares data properties that can be passed 1207 * on instantiation of the template. Properties can only be declared on 1208 * construction and are then immutable. The values are passed on creating the 1209 * object via `NewInstance()`. 1210 * 1211 * \param names the keys that can be passed on instantiation. 1212 */ 1213 static Local
New( 1214 Isolate* isolate, MemorySpan
names); 1215 1216 /** 1217 * Creates a new instance of this template. 1218 * 1219 * \param context The context used to create the dictionary object. 1220 * \param property_values Values of properties that were declared using 1221 * `DeclareDataProperties()`. The span only passes values and expectes the 1222 * order to match the declaration. Non-existent properties are signaled via 1223 * empty `MaybeLocal`s. 1224 */ 1225 V8_WARN_UNUSED_RESULT Local
NewInstance( 1226 Local
context, MemorySpan
> property_values); 1227 1228 V8_INLINE static DictionaryTemplate* Cast(Data* data); 1229 1230 private: 1231 static void CheckCast(Data* that); 1232 1233 DictionaryTemplate(); 1234 }; 1235 1236 /** 1237 * A Signature specifies which receiver is valid for a function. 1238 * 1239 * A receiver matches a given signature if the receiver (or any of its 1240 * hidden prototypes) was created from the signature's FunctionTemplate, or 1241 * from a FunctionTemplate that inherits directly or indirectly from the 1242 * signature's FunctionTemplate. 1243 */ 1244 class V8_EXPORT Signature : public Data { 1245 public: 1246 static Local
New( 1247 Isolate* isolate, 1248 Local
receiver = Local
()); 1249 1250 V8_INLINE static Signature* Cast(Data* data); 1251 1252 private: 1253 Signature(); 1254 1255 static void CheckCast(Data* that); 1256 }; 1257 1258 // --- Implementation --- 1259 1260 void Template::Set(Isolate* isolate, const char* name, Local
value, 1261 PropertyAttribute attributes) { 1262 Set(String::NewFromUtf8(isolate, name, NewStringType::kInternalized) 1263 .ToLocalChecked(), 1264 value, attributes); 1265 } 1266 1267 FunctionTemplate* FunctionTemplate::Cast(Data* data) { 1268 #ifdef V8_ENABLE_CHECKS 1269 CheckCast(data); 1270 #endif 1271 return reinterpret_cast
(data); 1272 } 1273 1274 ObjectTemplate* ObjectTemplate::Cast(Data* data) { 1275 #ifdef V8_ENABLE_CHECKS 1276 CheckCast(data); 1277 #endif 1278 return reinterpret_cast
(data); 1279 } 1280 1281 DictionaryTemplate* DictionaryTemplate::Cast(Data* data) { 1282 #ifdef V8_ENABLE_CHECKS 1283 CheckCast(data); 1284 #endif 1285 return reinterpret_cast
(data); 1286 } 1287 1288 Signature* Signature::Cast(Data* data) { 1289 #ifdef V8_ENABLE_CHECKS 1290 CheckCast(data); 1291 #endif 1292 return reinterpret_cast
(data); 1293 } 1294 1295 } // namespace v8 1296 1297 #endif // INCLUDE_V8_TEMPLATE_H_
Contact us
|
About us
|
Term of use
|
Copyright © 2000-2025 MyWebUniversity.com ™