Bug 193530

Summary: [webkit2gtk][JavaScriptCore glib] typeof "API created function" == "string"
Product: WebKit Reporter: li <crispyfrog>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: RESOLVED INVALID    
Severity: Normal Keywords: Gtk
Priority: P2    
Version: WebKit Local Build   
Hardware: PC   
OS: Linux   

Description li 2019-01-17 00:05:17 PST
I'm trying to use the JavaScriptCore glib API to define some native functions for use in user scripts, they work great so far, but somehow the js user script typeof doesn't recognize them as "function".
For example:

/* web-extension.c */
static void
zzz(void)
{	
	printf("zzz\n");
}

static void
windowobjectcleared(WebKitScriptWorld *w, WebKitWebPage *wp, WebKitFrame *frame,
                    gpointer unused)
{
	JSCContext *ctx;

	ctx = webkit_frame_get_js_context_for_script_world(frame, w);
	jsc_context_set_value(ctx, "zzz", jsc_value_new_function(
	  ctx, "zzz", (GCallback)zzz, NULL, NULL, G_TYPE_NONE, 0));
}

/* user-script.js */
console.log(typeof 'zzz');      /* logs string instead of function */
console.log(zzz);               /* function zzz() { [native code] } */
Comment 1 li 2019-01-17 04:36:50 PST
my bad, it's not a bug. I shouldn't have put quotes around the function name.