From be07858b2b9938051b19493058492b8353c7c884 Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Sat, 28 Jan 2006 20:39:07 +0000 Subject: [PATCH] Refactor the document.write routines Factor js_document_write_do out of js_document_write and js_document_writeln and document_write_do out of document_write and document_write_ln. --- src/ecmascript/see/document.c | 40 +++++++++----------------- src/ecmascript/spidermonkey/document.c | 30 ++++++++----------- 2 files changed, 25 insertions(+), 45 deletions(-) diff --git a/src/ecmascript/see/document.c b/src/ecmascript/see/document.c index 70b54d901..51ee5b50a 100644 --- a/src/ecmascript/see/document.c +++ b/src/ecmascript/see/document.c @@ -203,9 +203,9 @@ document_put(struct SEE_interpreter *interp, struct SEE_object *o, } static void -js_document_write(struct SEE_interpreter *interp, struct SEE_object *self, +js_document_write_do(struct SEE_interpreter *interp, struct SEE_object *self, struct SEE_object *thisobj, int argc, struct SEE_value **argv, - struct SEE_value *res) + struct SEE_value *res, int newline) { struct global_object *g = (struct global_object *)interp; struct view_state *vs = g->win->vs; @@ -217,6 +217,8 @@ js_document_write(struct SEE_interpreter *interp, struct SEE_object *self, if (code) { add_to_string(ret, code); mem_free(code); + if (newline) + add_char_to_string(ret, '\n'); } } #ifdef CONFIG_LEDS @@ -233,36 +235,20 @@ js_document_write(struct SEE_interpreter *interp, struct SEE_object *self, SEE_SET_BOOLEAN(res, 0); } +static void +js_document_write(struct SEE_interpreter *interp, struct SEE_object *self, + struct SEE_object *thisobj, int argc, struct SEE_value **argv, + struct SEE_value *res) +{ + js_document_write_do(interp, self, thisobj, argc, argv, res, 0); +} + static void js_document_writeln(struct SEE_interpreter *interp, struct SEE_object *self, struct SEE_object *thisobj, int argc, struct SEE_value **argv, struct SEE_value *res) { - struct global_object *g = (struct global_object *)interp; - struct view_state *vs = g->win->vs; - struct string *ret = g->ret; - - if (argc >= 1 && ret) { - unsigned char *code = SEE_value_to_unsigned_char(interp, argv[0]); - - if (code) { - add_to_string(ret, code); - mem_free(code); - add_char_to_string(ret, '\n'); - } - } -#ifdef CONFIG_LEDS - /* XXX: I don't know about you, but I have *ENOUGH* of those 'Undefined - * function' errors, I want to see just the useful ones. So just - * lighting a led and going away, no muss, no fuss. --pasky */ - /* TODO: Perhaps we can introduce ecmascript.error_report_unsupported - * -> "Show information about the document using some valid, - * nevertheless unsupported methods/properties." --pasky too */ - - set_led_value(vs->doc_view->session->status.ecmascript_led, 'J'); -#endif - checktime(interp); - SEE_SET_BOOLEAN(res, 0); + js_document_write_do(interp, self, thisobj, argc, argv, res, 1); } static int diff --git a/src/ecmascript/spidermonkey/document.c b/src/ecmascript/spidermonkey/document.c index 961fa8d2b..4dac5d72f 100644 --- a/src/ecmascript/spidermonkey/document.c +++ b/src/ecmascript/spidermonkey/document.c @@ -201,7 +201,8 @@ const JSFunctionSpec document_funcs[] = { }; static JSBool -document_write(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +document_write_do(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, + jsval *rval, int newline) { struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx); struct string *ret = interpreter->ret; @@ -210,6 +211,8 @@ document_write(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rv unsigned char *code = jsval_to_string(ctx, &argv[0]); add_to_string(ret, code); + if (newline) + add_char_to_string(ret, '\n'); } /* XXX: I don't know about you, but I have *ENOUGH* of those 'Undefined * function' errors, I want to see just the useful ones. So just @@ -227,24 +230,15 @@ document_write(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rv return JS_TRUE; } +static JSBool +document_write(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + + return document_write_do(ctx, obj, argc, argv, rval, 0); +} + static JSBool document_writeln(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx); - struct string *ret = interpreter->ret; - - if (argc >= 1 && ret) { - unsigned char *code = jsval_to_string(ctx, &argv[0]); - - add_to_string(ret, code); - add_char_to_string(ret, '\n'); - } - -#ifdef CONFIG_LEDS - set_led_value(interpreter->vs->doc_view->session->status.ecmascript_led, 'J'); -#endif - - boolean_to_jsval(ctx, rval, 0); - - return JS_TRUE; + return document_write_do(ctx, obj, argc, argv, rval, 1); }