Add bindings for Object::SetLazyDataProperty#1972
Conversation
Expose V8's Object::SetLazyDataProperty, which sets a property whose getter is called once on first access and then replaced with a plain data property.
fibibot
left a comment
There was a problem hiding this comment.
Substance is right.
v8__Object__SetLazyDataPropertyC++ binding signature matches V8'sSetLazyDataProperty(Local<Context>, Local<Name>, AccessorNameGetterCallback, Local<Value> data, PropertyAttribute attr, ...). ✓set_lazy_data_property/set_lazy_data_property_with_datasplit mirrors the existingset_accessor/set_accessor_with_datapattern in this file. ✓MapFnTo<AccessorNameGetterCallback>for the getter parameter is the standard rusty_v8 pattern;getter.map_fn_to()produces the FFI-safe function pointer. ✓null()for the no-data variant correctly maps to V8'sLocal<Value>empty case. ✓
The test is exactly the assertion I'd want — atomic counter + two evals + check the counter increments only once:
let actual = eval(scope, "obj.lazy_key").unwrap(); // first access
assert_eq!(CALL_COUNT.load(Ordering::SeqCst), 1);
let actual2 = eval(scope, "obj.lazy_key").unwrap(); // second access
assert_eq!(CALL_COUNT.load(Ordering::SeqCst), 1); // not 2 ✓This validates both halves of the contract: the getter fires on first read, and the slot is replaced with a plain data property afterward. Tight regression coverage.
Non-blocking — V8 has two more parameters
V8's full signature is:
Maybe<bool> SetLazyDataProperty(
Local<Context>, Local<Name>, AccessorNameGetterCallback,
Local<Value> data,
PropertyAttribute attr,
SideEffectType getter_side_effect_type = kHasSideEffect,
SideEffectType setter_side_effect_type = kHasSideEffectToReceiver
);The two SideEffectType parameters control whether DevTools' "evaluate without side effects" mode (used in console autocomplete + REPL evaluation) is allowed to invoke the getter. Defaults are sensible for most uses, so omitting them in the initial binding is fine. Worth a follow-up if a downstream consumer needs to mark a lazy getter as side-effect-free for inspector ergonomics.
CI
Mostly green; a few macos shards still pending. Already approved by @devsnek. Holding to COMMENT until the macos jobs settle, but substance is clean and I'd flip to APPROVE on green.
Summary
v8::Object::SetLazyDataPropertyset_lazy_data_property(simple) andset_lazy_data_property_with_data(with data + attributes)Test plan
object_set_lazy_data_propertytest)