Please allow setting PropertyHandlerFlags of NamedPropertyHandlerConfiguration
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.4k
- Forks
- 531
- Avg merge
- 21m
- Merged PRs (30d)
- 1
Description
I have a named property interceptor and I use Nan::SetNamedPropertyHandler so that it works accross multiple node versions.
auto doctpl = Nan::New<FunctionTemplate>(DocumentWrap::ctor);
doctpl->SetClassName(Nan::New<String>("Document").ToLocalChecked());
doctpl->InstanceTemplate()->SetInternalFieldCount(1);
// Instance functions
Nan::SetPrototypeMethod(doctpl, "getTokenizerForField", DocumentWrap::getTokenizerForField);
Nan::SetPrototypeMethod(doctpl, "setTokenizerForField", DocumentWrap::setTokenizerForField);
Nan::SetPrototypeMethod(doctpl, "destroy", DocumentWrap::destroy);
Nan::SetPrototypeMethod(doctpl, "disableIndexingForField", DocumentWrap::disableIndexingForField);
// Interceptor for docid and fields
Nan::SetNamedPropertyHandler(
doctpl->InstanceTemplate(),
DocumentWrap::getField,
DocumentWrap::setField,
DocumentWrap::queryField,
DocumentWrap::removeField,
DocumentWrap::enumerateField
);
// Create constructor function
auto docctor = doctpl->GetFunction();
// Save persistent handle
documentWrapCtor.Reset(docctor);
The trouble is that the object also has some functions set on its prototype. By default, v8 uses the named property interceptor even if the user wants to call one of these functions:
doc.getTokenizerForField("hello", "world");
This results in a TypeError: doc.setTokenizerForField is not a function
The issue can be solved if one sets the correct PropertyHandlerFlags to the NamedPropertyHandlerConfiguration, however currently nan doesn't let me do this.
I suggest to simply add one more argument to Nan::SetNamedPropertyHandler.
For the sake of completeness, the flags I need to use are:
- v8::PropertyHandlerFlags::kNonMasking
- v8::PropertyHandlerFlags::kOnlyInterceptStrings
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating Nan::SetNamedPropertyHandler and the construction of V8's NamedPropertyHandlerConfiguration. Check how handler arguments are supported across the Node/V8 versions Nan targets, then make the requested flags pass-through available. Done means callers can supply kNonMasking and kOnlyInterceptStrings so prototype functions are not intercepted, with compatibility coverage where the project provides it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, nodejs
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100