[webkit-help] New to webkit

LG lgmagic at gmail.com
Mon Aug 3 04:56:53 PDT 2009


Hi Jack,

thanks for the info,

the problem here is i tried this and didnot work
i ll elaborate on what i have tried

1. i have created a class in JavascriptCore/API

test.cpp

#include "UnusedParam.h"
#include <JavaScriptCore/JavaScript.h>
#include <assert.h>
#include <math.h>
#include <setjmp.h>


static JSGlobalContextRef context = 0;
JSValueRef v;
JSValueRef exception;
JSStringRef functionBody;
JSObjectRef function;

int main()
{

    //create a class with a name
    JSStringRef calObjectName = JSStringCreateWithUTF8CString("calendar");

    //create a class definition
    JSClassDefinition calObjectDef;
    calObjectDef.version = 1;
    //calObjectDef.className = calObjectName


    //create a context
    //context = JSGlobalContextCreate(NULL);
    //assert(JSValueIsObject(context, globalObject));

    //create the class
    JSClassRef globalObjectClass = JSClassCreate(&calObjectDef);

    //create a global context
    JSGlobalContextRef context = JSGlobalContextCreate(globalObjectClass);
        JSObjectRef globalObject = JSContextGetGlobalObject(context);

    //make the object
    JSObjectRef calObject = JSObjectMake(context, globalObjectClass, NULL);


    //set properties
    JSObjectSetProperty(context, globalObject, calObjectName, calObject,
kJSPropertyAttributeNone, NULL);


    exception = NULL;
    v = NULL;

    JSStringRef getCal = JSStringCreateWithUTF8CString("getCalendars");
    functionBody = JSStringCreateWithUTF8CString("return NULL;");
    function = JSObjectMakeFunction(context, getCal,0, NULL, functionBody,
NULL, 1, &exception);
    assert(function && !exception);
    JSValueRef arguments[] = { JSValueMakeNumber(context, 2) };
    v = JSObjectCallAsFunction(context, function, NULL, 1, arguments,
&exception);
    JSStringRelease(getCal);
    JSStringRelease(functionBody);

    return 1;
}


2. i added this to the make file and i get the following errors

undefined reference to `JSStringCreateWithUTF8CString`
undefined reference to `JSClassCreate`
undefined reference to `JSGlobalContextCreate`

etc

i am not sure where to put the file and compile
please guide me through the approach




On Mon, Aug 3, 2009 at 2:29 PM, Jack Wootton <jackwootton at gmail.com> wrote:

> Hello,
>
> If you mean add a new JavaScript object, then here is a reply I wrote
> some time ago (copied and pasted).
>
> Here is the API:
>
>
> http://gemma.apple.com/documentation/Carbon/Reference/WebKit_JavaScriptCore_Ref/index.html#//apple_ref/doc/framework/javascriptcore_fw
>
> If this is what you wish to do, then the following is a rough guide of
> what you need to do:
>
> 1. Create an empty class definition, you can create an empty class
> definition using kJSClassDefinitionEmpty.
> 2. Use the class definition with the JSCoreAPI method "JSClassCreate"
> to create your class.
> 3. Use your new class with JSObjectMake to create your new JSObject
> (this will be your widget object).
> 4  Use JSObjectSetProperty to add your new JSObject as a property of
> the Window object.
>
> It maybe useful to look at the following files in the
> JavaScriptCore (Although, personally I didn't find them particularly
> easy to understand.)
>
> JavaScriptCore\API\testapi.c
> testapi.js
>
>
> There are also some example programs that do what you want to do, only
> with different objects.
>
> JSPong: http://developer.apple.com/SampleCode/JSPong/index.html
>
> JSInterpreter:
> http://developer.apple.com/samplecode/JSInterpreter/index.html
>
> More programs can be found here:
>
> http://developer.apple.com/SampleCode/Cocoa/idxInternetWeb-date.html
>
> On Mon, Aug 3, 2009 at 5:34 AM, LG<lgmagic at gmail.com> wrote:
> > Hi all,
> >
> > i am new to webkit and i need to add an new object/api to javascript core
> > can someone share and example and tell me how to compile it in webkit
> >
> > anyhelp would be useful
> > thanks a lot
> >
> >
> > --
> > Ganesh
> >
> > _______________________________________________
> > webkit-help mailing list
> > webkit-help at lists.webkit.org
> > http://lists.webkit.org/mailman/listinfo.cgi/webkit-help
> >
> >
>
>
>
> --
> Regards
> Jack
>



-- 
LG
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-help/attachments/20090803/b510b999/attachment.html>


More information about the webkit-help mailing list