From 30ccbaaf212f002ffc5e014949fcfc204e0fe534 Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Sun, 18 Dec 2005 17:49:21 +0000 Subject: [PATCH] Add the elinks.alert method. --- src/scripting/smjs/elinks_object.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/scripting/smjs/elinks_object.c b/src/scripting/smjs/elinks_object.c index 73310d06..449669b2 100644 --- a/src/scripting/smjs/elinks_object.c +++ b/src/scripting/smjs/elinks_object.c @@ -12,6 +12,25 @@ #include "scripting/smjs/elinks_object.h" +static JSBool +elinks_alert(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + unsigned char *string; + + if (argc != 1) + return JS_TRUE; + + string = jsval_to_string(ctx, &argv[0]); + if (!*string) + return JS_TRUE; + + alert_smjs_error(string); + + undef_to_jsval(ctx, rval); + + return JS_TRUE; +} + static const JSClass elinks_class = { "elinks", 0, @@ -20,10 +39,15 @@ static const JSClass elinks_class = { JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub }; +static const JSFunctionSpec elinks_funcs[] = { + { "alert", elinks_alert, 1 }, + { NULL } +}; + JSObject * smjs_get_elinks_object(JSObject *global_object) { return JS_InitClass(smjs_ctx, global_object, NULL, (JSClass *) &elinks_class, NULL, 0, NULL, - NULL, NULL, NULL); + (JSFunctionSpec *) elinks_funcs, NULL, NULL); }