I have an application that extends JavaScript via JavaScriptCore, in a webkit-gtk browser. Right now I have several classes that I add to the global context like so:
void create_js(gpointer context, char* className, JSClassDefinition clasDefinition) {
JSClassRef classDef = JSClassCreate(&clasDefinition);
JSObjectRef classObj = JSObjectMake(context, classDef, context);
JSObjectRef globalObj = JSContextGetGlobalObject(context);
JSStringRef str = JSStringCreateWithUTF8CString(className);
JSObjectSetProperty(context, globalObj, str, classObj, kJSPropertyAttributeNone, NULL);
JSStringRelease(str);
}
Now, I'd like to also add those classes to the WebWorker's context, so I can call them from workers instantiated in JS.
I've tried getting the Worker
object like so:
JSStringRef workerStr = JSStringCreateWithUTF8CString("Worker");
JSObjectRef worker = JSObjectGetProperty(context, globalObj, workerStr, NULL);
JSObjectSetProperty(context, worker, str, classObj, kJSPropertyAttributeNone, NULL);
JSStringRelease(workerStr);
But that adds it to the WorkerConstructor
object, and when a new Worker()
is called, the classes are not available.
Worker
class definition. Normally you need to add your class to the Global object and to every Global Object within a new created JSVirtualMachine.Worker
will create a newJSVirtualMachine
with it's global context and global object; a totally seperated environement – Selfassertion