Bug 184907

Summary: JSC needs to provide a basic handle api
Product: WebKit Reporter: Oliver Hunt <oliver>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: fpizlo, jfbastien, mark.lam, oliver
Priority: P2    
Version: Other   
Hardware: Unspecified   
OS: Unspecified   

Description Oliver Hunt 2018-04-23 22:53:09 PDT
I'm trying to write an "interesting" js program and it keeps being frustrating to try and manage lifetime in the C API.

The problems that I keep hitting is that JSValueProtect/Unprotect require a context argument, that means a smart pointer has to carry both the value and context references.

The other problem is weak and conditional ownership.

I think an API along the lines of

typedef JSHandleRef

JSHandleRef JSHandleMake(JSContextRef)
JSHandleRef JSHandleMakeWeak(JSContextRef, nullable JSWeakCallback)

// Note the lack of a context here -- I believe that is completely achievable.
void JSHandleRetain(JSHandleRef)
void JSHandleRelease(JSHandleRef)

// While it would be nice to just have a "get slot" style api, I think that would
// result in ABI heartbreak down the road
JSValueRef JSHandleGetValue(JSHandleRef)
void JSHandleSetValue(JSHandleRef, JSValueRef)