JavaScriptCore / JSExport: Swift methods throwing errors not exported to JavaScript

Originator:hello
Number:rdar://48767173 Date Originated:2019-03-11
Status:Open Resolved:
Product:macOS + SDK / JavaScriptCore Product Version:10.14.3
Classification:Bug Reproducible:Always
 
Methods included in a JSExport protocol in Swift are not exported if they are throwing errors.

// Custom protocol must be declared with `@objc`
@objc public protocol PersonJSExports : JSExport {
    /// Not exported because of `throws`
    func greet() throws
}

The greet function in the example above is not exported, resulting in the following message.

TypeError: person.greet is not a function. (In 'person.greet()', 'person.greet' is undefined)

The expected behaviour would be to to run `greet()` and throw any error produced within the method in order to handle it properly within JavaScript using a `try...catch...finally block.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!