[jsc-dev] How to use JSExport and JavascriptCore in C++

Geoffrey Garen ggaren at apple.com
Wed Oct 25 16:53:49 PDT 2017


Hi Alexis.

You’ll either need to convert your C++ objects to Objective-C objects, wrap your C++ objects in Objective-C objects, or use JavaScriptCore’s C API.

Regards,
Geoff

> On Oct 25, 2017, at 4:39 PM, Alexis Barra <alexis.barra at gmail.com> wrote:
> 
> I'm working with JavascriptCore in a C++ project and I don't know how to expose a C++ class to javascript. For example in Objective-C is something like this:
> 
> @protocol MyPointExports <JSExport>
> @property double x;
> @property double y;
> - (NSString *)description;
> - (instancetype)initWithX:(double)x y:(double)y;
> + (MyPoint *)makePointWithX:(double)x y:(double)y;
> @end
> 
> @interface MyPoint : NSObject <MyPointExports>
> - (void)myPrivateMethod;  // Not in the MyPointExports protocol, so not visible to JavaScript code.
> @end
> 
> @implementation MyPoint
> // ...
> @end
> 
> JSContext *context = [[JSContext alloc] init];
> 
> // export MyPoint class
> context[@"MyPoint"] = [MyPoint class];
> But I have not idea how to translate JSExport and protocol into C++.
> 
> 
> -- 
> Alexis Barra.
> 
> _______________________________________________
> jsc-dev mailing list
> jsc-dev at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/jsc-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/jsc-dev/attachments/20171025/5f8cb837/attachment-0001.html>


More information about the jsc-dev mailing list