diff options
author | portix <none@none> | 2013-01-26 13:24:31 +0100 |
---|---|---|
committer | portix <none@none> | 2013-01-26 13:24:31 +0100 |
commit | 83da4f3b781fd56d0c88db99c8cc64c86ba6309f (patch) | |
tree | 581b3478c3b934325239f557e70b9aa7e4c6dd97 /src/scripts.c | |
parent | 0082dad9b0c87fcb01d7ca72c16eb6a1d7e131db (diff) | |
download | dwb-83da4f3b781fd56d0c88db99c8cc64c86ba6309f.zip |
Implementing tabs.iterate
Diffstat (limited to 'src/scripts.c')
-rw-r--r-- | src/scripts.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/scripts.c b/src/scripts.c index f3989656..a4311d8a 100644 --- a/src/scripts.c +++ b/src/scripts.c @@ -338,6 +338,23 @@ tabs_length(JSContextRef ctx, JSObjectRef this, JSStringRef name, JSValueRef* ex return JSValueMakeNumber(ctx, g_list_length(dwb.state.views)); }/*}}}*/ +static JSValueRef +tabs_iterate(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc) +{ + JSObjectRef callback; + if (argc == 0 || (callback = js_value_to_function(ctx, argv[0], exc)) == NULL) + return UNDEFINED; + int i=0; + for (GList *l = dwb.state.views; l; l=l->next) + { + JSValueRef args[] = { VIEW(l)->script_wv, JSValueMakeNumber(ctx, i++) }; + JSValueRef ret = JSObjectCallAsFunction(ctx, callback, callback, 2, args, exc); + if (JSValueToBoolean(ctx, ret)) + break; + } + return UNDEFINED; +} + /* tabs_get_nth {{{*/ static JSValueRef tabs_get_nth(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc) @@ -2557,6 +2574,7 @@ create_global_object() JSStaticFunction tab_functions[] = { { "nth", tabs_get_nth, kJSDefaultAttributes }, + { "iterate", tabs_iterate, kJSDefaultAttributes }, { 0, 0, 0 }, }; JSStaticValue tab_values[] = { |