JavaScriptKit icon indicating copy to clipboard operation
JavaScriptKit copied to clipboard

Do we need new enum cases in `JSValue` for closures?

Open MaxDesiatov opened this issue 4 years ago • 2 comments

Now that JSClosure and JSOneshotClosure are no longer subclasses of JSFunction, how are they supposed to be converted to JSValue? Should the object case be used?

MaxDesiatov avatar Jan 18 '21 20:01 MaxDesiatov

I think the object case should be used for this purpose because we don't need to distinguish object case and closure case internally. If you want API consistency, we can add a new static func instead of a new case.

static func closure(_ closure: JSClosure) -> JSValue { .object(closure) }

kateinoigakukun avatar Jan 19 '21 11:01 kateinoigakukun

Yeah, that would make sense, I can see people being confused when there is JSValue.function, but no JSValue.closure

MaxDesiatov avatar Jan 19 '21 11:01 MaxDesiatov