Repository navigation
fix(jsi): complete V8Runtime NativeState, MutableBuffer ArrayBuffer, and ExternalMemoryAccounter support - #510
NathanWalker wants to merge 1 commit into
Conversation
…and ExternalMemoryAccounter support
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to No actionable issue was established that needs to be fixed before merging. Complete the normal build and runtime checks. Pre-merge checks ·
|
|
Moving to optional external package |
Summary
Completes key
facebook::jsi::Runtimecapabilities inrnv8::V8Runtimerequired by JSI consumers andNitroModules(HybridObject/Prototype/ zero-copyArrayBuffer/NativeState):Fix
V8Runtime::setNativeStateweak handle lifecycle & prototype preservationweakV8ObjectinV8Runtime::setNativeStatewas previously stack-allocated (v8::Global<v8::Object> weakV8Object(isolate_, v8Object)), so its destructor ran whensetNativeStatereturned, immediately resetting the global handle and cancelling the weak finalizer callback (leaking the heap-allocatedstd::shared_ptr<jsi::NativeState>).NativeStateHolderon the heap withv8::WeakCallbackType::kParameter(matchingHostObjectProxy::Finalizer) sostd::shared_ptr<jsi::NativeState>is deterministically released when the V8 object is collected.v8ObjectOriginal->GetPrototype()->v8Object->SetPrototype(context, prototype)) when replacing a 0-internal-fieldv8::Objectwith a 2-internal-fieldkNativeStateinstance, and updatesNativeStateHolder::statein place whensetNativeStateis called again on an object that already holdskNativeState.GetInternalFieldTypewhen internal field 0 is not aUint32.Direct V8 prototype operations (
createObjectWithPrototype,setPrototypeOf,getPrototypeOf)createObjectWithPrototype,setPrototypeOf, andgetPrototypeOfonV8Runtimeusingv8::Object::SetPrototype/GetPrototypedirectly.createObjectWithPrototypepre-allocate 2 internal fields initialized toInternalFieldType::kInvalidso subsequentsetNativeStatecalls populate internal field 1 in place without replacing V8 object identity or invokingObject.assign.Implement
V8Runtime::createArrayBuffer(std::shared_ptr<jsi::MutableBuffer>)std::logic_error("Not implemented")stub with a zero-copyv8::ArrayBuffer::NewBackingStorebacked by thestd::shared_ptr<jsi::MutableBuffer>, releasing the shared pointer in theBackingStoredeleter callback when V8 collects or detaches theArrayBuffer.Implement
V8Runtime::setExternalMemoryPressurev8::ExternalMemoryAccounterand a private key (v8::Private::ForApi), supporting repeated updates on the same object and decrementing the accounted bytes when the object is garbage-collected.Summary by CodeRabbit