[webkit-dev] Identifying Views / Windows inside

Jack Wootton jackwootton at gmail.com
Fri Jun 5 01:41:52 PDT 2009


Hello,

I'm, using JSObjectCallAsFunctionCallback to specify a C function
which maps to a JavaScript function.  So the code looks like this:

// This is the C function that contains the implementation of the
JavaScript function.

static JSValueRef JS_myFunc(JSContextRef ctx,
						JSObjectRef function,
						JSObjectRef thisObject,
						size_t argumentCount,
						const JSValueRef arguments[],
						JSValueRef *exception)
	{
        // Implementation goes here.
	}

// Store the function pointer.

JSObjectCallAsFunctionCallback C_myFunc = JS_myFunc;

// The name of the function in JavaScript.

char funcName[] = { 'f', 'o', 'o', '\0' };

// Create an array of JSStaticFunctions for use with JSClassDefinition

JSStaticFunction JS_staticFuncs[2] =
	  {
			  {funcName, C_myFunc, kJSPropertyAttributeNone},
			  {0, 0, 0}
	  };


char toStringVal[] = { 'f', 'o', 'o', '\0' };

// Use the function definitions when creating a class definition so that they
// are added to the staticFunctions data-member of the JSClassDefinition enum.

JSClassDefinition globalObjectClassDefinition =
	  {
			  1, kJSPropertyAttributeNone, toStringVal, 0,
			  0, JS_staticFuncs,, 0, 0,
			  0, 0, 0, 0,
			  0, 0, 0, 0,
			  0
	  };

I have a few questions about the C function that actually contains the
implementation (JSObjectCallAsFunctionCallback).

1. Does it have to be static?  If so what impact does this have if the
function is called multiple times. It seems that the function

static JSValueRef JS_myFunc(JSContextRef ctx,
						JSObjectRef function,
						JSObjectRef thisObject,
						size_t argumentCount,
						const JSValueRef arguments[],
						JSValueRef *exception)
	{
        // Implementation here.
	}

Could enter multiple times, but is static.

2. If I wished to call a JavaScript function belonging to the Window
JSObjectRef, from within the above function.  Then the following steps
would be used inside the above function:

a. Create string name of the JS function to call using
JSStringCreateWithUTF8CString.
b. Use JSObjectGetProperty to get a property of the Window object
which contains the JavaScript function to call.
c. Use JSValueToObject to convert the JSValueRef to a JSObjectRef.
d. Use JSObjectCallAsFunction, to call the function as a property of
the Window object.

However there seems to be a problem here.  Step 'b' is getting a
property of the Window object since when the JavaScriptCore parsed the
web page, it would have added any functions to the Window object as
properties of that Window object. In order to get a property of the
Window object I need the JSObjectRef of the Window.  But I do not have
it inside the function.

-- 
Regards
Jack


More information about the webkit-dev mailing list