diff options
-rw-r--r-- | api/jsapi.txt | 36 | ||||
-rw-r--r-- | src/scripts.c | 34 | ||||
-rw-r--r-- | src/util.c | 5 |
3 files changed, 71 insertions, 4 deletions
diff --git a/api/jsapi.txt b/api/jsapi.txt index ca470382..3b77b81b 100644 --- a/api/jsapi.txt +++ b/api/jsapi.txt @@ -358,6 +358,24 @@ _error_;; A javascript error object, optional as second parameter **** **** +[[dirNames]] +[float] +==== *dirNames()* ==== + +[source,javascript] +---- +Array io.dirNames(String path) +---- + +Get directory entries. + + :: + +_path_;; A path to a directory +_returns_;; An array with the directory names +**** + +**** [[error]] [float] ==== *error()* ==== @@ -1321,6 +1339,24 @@ _webview_;; The <<webview>> that corresponds to the tab **** **** +[[documentLoaded]] +[float] +==== *documentLoaded* ==== + +[source,javascript] +---- +void callback(webview, frame) +---- + +Emitted when a the dom document of an frame has loaded. + + :: + +_webview_;; The <<webview>> that emitted the signal +_frame_;; The frame that contains the document +**** + +**** [[download]] [float] ==== *download* ==== diff --git a/src/scripts.c b/src/scripts.c index 17a1243d..64fd7a0c 100644 --- a/src/scripts.c +++ b/src/scripts.c @@ -1122,6 +1122,35 @@ io_error(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t return JSValueMakeUndefined(ctx); }/*}}}*/ +static JSValueRef +io_dir_names(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc) { + JSValueRef ret; + if (argc < 1) { + js_make_exception(ctx, exc, EXCEPTION("io.dirNames: missing argument.")); + return JSValueMakeNull(ctx); + } + GDir *dir; + char *dir_name = js_value_to_char(ctx, argv[0], PATH_MAX, exc); + const char *name; + GSList *list = NULL; + if (dir_name == NULL) + return JSValueMakeNull(ctx); + if ((dir = g_dir_open(dir_name, 0, NULL)) != NULL) { + while ((name = g_dir_read_name(dir)) != NULL) { + list = g_slist_prepend(list, (gpointer)js_char_to_value(ctx, name)); + } + g_dir_close(dir); + JSValueRef args[g_slist_length(list)]; + int i=0; + for (GSList *l = list; l; l=l->next, i++) + args[i] = l->data; + ret = JSObjectMakeArray(ctx, i, args, exc); + } + else + ret = JSValueMakeNull(ctx); + g_free(dir_name); + return ret; +} /* io_write {{{*/ static JSValueRef io_write(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc) { @@ -1585,11 +1614,12 @@ create_global_object() { JSStaticFunction io_functions[] = { { "print", io_print, kJSDefaultAttributes }, - { "prompt", io_prompt, kJSDefaultAttributes }, + { "prompt", io_prompt, kJSDefaultAttributes }, { "read", io_read, kJSDefaultAttributes }, { "write", io_write, kJSDefaultAttributes }, + { "dirNames", io_dir_names, kJSDefaultAttributes }, { "notify", io_notify, kJSDefaultAttributes }, - { "error", io_error, kJSDefaultAttributes }, + { "error", io_error, kJSDefaultAttributes }, { 0, 0, 0 }, }; class = create_class("io", io_functions, NULL); @@ -247,11 +247,12 @@ util_get_directory_content(GString *buffer, const char *dirname, const char *ext GDir *dir; char *content; GError *error = NULL; - char *filename, *filepath; + const char *filename; + char *filepath; char *firstdot; if ( (dir = g_dir_open(dirname, 0, NULL)) ) { - while ( (filename = (char*)g_dir_read_name(dir)) ) { + while ( (filename = g_dir_read_name(dir)) ) { if (*filename == '.') continue; if (extension) { |