In the V8 embedding guide in the section for accessing dynamic variables, it describes how to write a setter for a wrapped C++ object. But the documentation seems to have rotted a bit in its usage of ToInt32
compared to the current (v14.1) API.
This example...
void SetPointX(v8::Local<v8::String> property, v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
v8::Local<v8::Object> self = info.Holder();
v8::Local<v8::External> wrap =
v8::Local<v8::External>::Cast(self->GetInternalField(0));
void* ptr = wrap->Value();
static_cast<Point*>(ptr)->x_ = value->Int32Value();
}
...calls v8::Local<v8::Value>::Int32Value()
but no such parameterless overload returning something that can be converted to an int
exists any more. In the current API, the function requires a v8::Local<v8::Context>
argument, and returns a v8::Maybe<int32_t>
.
How would one modify this SetPointX
function to gain access to the Context
and deal with the Maybe
that ToInt32
returns?