The AccessorInfo class is a part of the V8 C++ API, which allows developers to create and manipulate JavaScript objects in C++ code. The AccessorInfo class provides information about an accessor method (a special type of method that allows for getting and setting properties) that is being called by JavaScript code.
Some examples of using the AccessorInfo class in C++ code might include creating a custom getter or setter for a property on a JavaScript object, or implementing a custom logic for how certain properties are read or written to.
Here is an example of how the AccessorInfo class might be used to implement a custom getter for a "message" property on an object in C++ code:
```c++
void GetHandler(v8::Local name, const v8::PropertyCallbackInfo& info) {
// Retrieve the JavaScript object that the accessor is being called on
v8::Local obj = info.This();
// Retrieve the value of the "message" property on the object
v8::Local msg = obj->GetInternalField(0);
// Return the value of the "message" property to the JavaScript caller
info.GetReturnValue().Set(msg);
}
// Define an object template with a custom accessor for the "message" property
v8::Local obj_template = v8::ObjectTemplate::New(isolate);
obj_template->SetAccessor(
v8::String::NewFromUtf8(isolate, "message"),
GetHandler,
nullptr,
v8::Local(),
v8::AccessControl::ALL_CAN_READ,
v8::PropertyAttribute::DontEnum
);
// Create an object instance from the object template and set a message property
v8::Local obj = obj_template->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
obj->SetInternalField(0, v8::String::NewFromUtf8(isolate, "Hello world!"));
```
This example code sets up an object template with a custom getter for the "message" property, then creates an instance of the template and sets a value for that property. When the "message" property is accessed in JavaScript code, the custom getter implemented using the AccessorInfo class is called, and the value of the property is returned.
The V8 AccessorInfo class is a part of the V8 API, which is included as a library within the V8 engine itself.
C++ (Cpp) AccessorInfo - 30 examples found. These are the top rated real world C++ (Cpp) examples of v8::AccessorInfo extracted from open source projects. You can rate examples to help us improve the quality of examples.