diff options
author | portix <none@none> | 2012-04-18 12:42:49 +0200 |
---|---|---|
committer | portix <none@none> | 2012-04-18 12:42:49 +0200 |
commit | fdc89e8328b2386259ac53f619f497655b87783c (patch) | |
tree | 0b4f099cd4ac51686de14465131a2c9beed6c5c6 | |
parent | e9bb365b9be5f67d20c899af4e5a084daaad9670 (diff) | |
download | dwb-fdc89e8328b2386259ac53f619f497655b87783c.zip |
Return id from connect
--HG--
branch : scripts
-rw-r--r-- | api/jsapi.txt | 23 | ||||
-rw-r--r-- | scripts/lib/signals.js | 36 | ||||
-rw-r--r-- | src/scripts.c | 34 |
3 files changed, 69 insertions, 24 deletions
diff --git a/api/jsapi.txt b/api/jsapi.txt index 8a69a90f..0b90308d 100644 --- a/api/jsapi.txt +++ b/api/jsapi.txt @@ -26,7 +26,7 @@ also <<Encapsulation>>). === Global functions === Functions from the global object. -[options="header", cols="1s,1s,2,2,3"] +[options="header", cols="1s,1s,2,2,4"] |============================================= |function 2+| parameter | returns |description @@ -55,7 +55,7 @@ execute("tabopen ixquick.com"); === io === A global object that implements functions for input and output. -[options="header", cols="1s,1s,2,2,3"] +[options="header", cols="1s,1s,3,2,2"] |============================================= |function 2+| parameter | returns |description .2+|print @@ -88,7 +88,7 @@ io.print(text); A global object that implements system functions. -[options="header", cols="1s,1s,2,2,3"] +[options="header", cols="1s,1s,2,2,2"] |============================================= |function 2+| parameter | returns |description |spawn @@ -113,7 +113,7 @@ system.spawn("xterm -e vim " + home + "/.bashrc"); The webview object represents the widget that actually displays the site content. The webview object will be the first parameter of every signal function. -[options="header", cols="1s,1s,2,2,3"] +[options="header", cols="1s,1s,2,2,4"] |============================================= |function 2+| parameter | returns |description |set @@ -163,7 +163,7 @@ signals.onNavigation = function (o, obj) { === tabs === A global object that implements functions to get webview objects. -[options="header", cols="1s,1s,2,2,3"] +[options="header", cols="1s,1s,3,2,2"] |============================================= |function 2+| parameter | returns |description @@ -239,22 +239,21 @@ which contains values relevant to the signal. The signals object implements the following functions -[options="header", cols="1s,1s,2,2,3"] +[options="header", cols="1s,1s,3,2,2"] |============================================= |function 2+| parameter | returns | description -.2+|connect |signal |The signal name to connect to; required .2+| - +.2+|connect |signal |The signal name to connect to; required .2+| The +signal id of the signal. .2+| Connects to a signal. -If you want to disconnect from that signal +callback+ may not be a closure. |callback | The callback to call when the signal is emitted -.2+|disconnect -|signal |The signal name to disconnect; required .2+| - -.2+| Disconnects from a signal. The parameters must be the same as passed to +|disconnect +|id |The signal id to disconnect; required | - +| Disconnects from a signal, the id is the id returned by +connect+. -|callback | The callback passed to connect .3+|emit |signal |The signal name to emit; required .3+| - diff --git a/scripts/lib/signals.js b/scripts/lib/signals.js index b01b2361..74b8e31f 100644 --- a/scripts/lib/signals.js +++ b/scripts/lib/signals.js @@ -1,32 +1,44 @@ -Object.defineProperty(signals, "registered", { +Object.defineProperty(signals, "_registered", { value : {} }); +Object.defineProperty(signals, "_maxId", { + value : 0, + writable : true +}); Object.defineProperty(signals, "emit", { value : function(sig, wv, o) { - var sigs = signals.registered[sig]; + var sigs = signals._registered[sig]; for (var i=0; i<sigs.length; i++) { - sigs[i](wv, o); + sigs[i].callback(wv, o); } } }); Object.defineProperty(signals, "connect", { value : function(sig, func) { - var connected = signals.registered[sig] !== undefined && signals.registered[sig] !== null; - if (!connected) - signals.registered[sig] = []; - signals.registered[sig].push(func); - if (!connected) { + signals._maxId++; + io.print(signals._maxId); + if (signals._registered[sig] === undefined || signals._registered[sig] === null) { + signals._registered[sig] = []; signals[sig] = function (wv, o) { signals.emit(sig, wv, o); }; } + signals._registered[sig].push({callback : func, id : signals._maxId }); + return signals._maxId; } }); Object.defineProperty(signals, "disconnect", { - value : function(sig, func) { - var sigs = signals.registered[sig]; - if (sigs) - delete sigs.splice(sigs.indexOf(func), 1); + value : function(id) { + var s, i, a; + for (s in signals._registered) { + a = signals._registered[s]; + for (i = 0; i<a.length; i++) { + if (a[i].id == id) { + delete a.splice(i, 1); + } + } + } } }); +io.print("a :" + a); diff --git a/src/scripts.c b/src/scripts.c index 78b97170..280e1ca0 100644 --- a/src/scripts.c +++ b/src/scripts.c @@ -61,6 +61,40 @@ static JSObjectRef _signals; static JSClassRef _viewClass; static GString *_script; +#if 0 +gboolean +scripts_print_exception(JSContextRef ctx, JSValueRef exception) { + gboolean ret = false; + char *message = NULL; + if (!JSValueIsObject(ctx, exception)) + return false; + JSObjectRef o = JSValueToObject(ctx, exception, NULL); + if (o == NULL) + return false; + + double line = js_get_double_property(ctx, o, "line"); + if (line == NAN) + return false; + message = js_get_string_property(ctx, o, "message"); + if (message == NULL) + goto error_out; + fprintf(stderr, "EXCEPTION in line %d: %s\n", (int)line, message); + ret = true; +error_out: + g_free(message); + return ret; +} +void +scripts_exception(JSContextRef ctx, JSValueRef *exception, const gchar *format, ...) { + va_list arg_list; + + va_start(arg_list, format); + gchar message[JS_STRING_MAX]; + vsnprintf(message, JS_STRING_MAX, format, arg_list); + va_end(arg_list); + *exception = js_char_to_value(ctx, message); +} +#endif JSClassRef scripts_create_class(const char *name, JSStaticFunction staticFunctions[], JSStaticValue staticValues[]) { JSClassDefinition cd = kJSClassDefinitionEmpty; |