Bug 184907 - JSC needs to provide a basic handle api
Summary: JSC needs to provide a basic handle api
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
Depends on:
Reported: 2018-04-23 22:53 PDT by Oliver Hunt
Modified: 2018-04-23 22:53 PDT (History)
4 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
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)