mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
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.
This commit is contained in:
parent
5bcb1309da
commit
be07858b2b
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user