mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[console] console.error and fixes in jsval_to_string
This commit is contained in:
parent
b8ddbeef0f
commit
5737a4d345
@ -81,6 +81,7 @@ static int interpreter_count;
|
||||
static INIT_LIST_OF(struct string_list_item, allowed_urls);
|
||||
static INIT_LIST_OF(struct string_list_item, disallowed_urls);
|
||||
|
||||
char *console_error_filename;
|
||||
char *console_log_filename;
|
||||
|
||||
char *local_storage_filename;
|
||||
@ -542,13 +543,11 @@ init_ecmascript_module(struct module *module)
|
||||
{
|
||||
read_url_list();
|
||||
|
||||
if (elinks_home) {
|
||||
/* ecmascript console log */
|
||||
if (elinks_home) {
|
||||
console_log_filename = straconcat(elinks_home, "/console.log", NULL);
|
||||
}
|
||||
|
||||
console_error_filename = straconcat(elinks_home, "/console.err", NULL);
|
||||
/* ecmascript local storage db location */
|
||||
if (elinks_home) {
|
||||
local_storage_filename = straconcat(elinks_home, "/elinks_ls.db", NULL);
|
||||
}
|
||||
}
|
||||
|
@ -119,6 +119,7 @@ int get_ecmascript_enable(struct ecmascript_interpreter *interpreter);
|
||||
|
||||
void check_for_rerender(struct ecmascript_interpreter *interpreter, const char* text);
|
||||
|
||||
extern char *console_error_filename;
|
||||
extern char *console_log_filename;
|
||||
|
||||
extern char *local_storage_filename;
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <jsapi.h>
|
||||
#include <jsfriendapi.h>
|
||||
#include <js/Conversions.h>
|
||||
|
||||
#include "util/string.h"
|
||||
|
||||
@ -47,8 +48,7 @@ static inline char *
|
||||
jsval_to_string(JSContext *ctx, JS::HandleValue hvp)
|
||||
{
|
||||
/* Memory must be freed in caller */
|
||||
|
||||
JSString *st = hvp.toString();
|
||||
JSString *st = JS::ToString(ctx, hvp);
|
||||
JS::RootedString rst(ctx, st);
|
||||
JS::UniqueChars utf8chars = JS_EncodeStringToUTF8(ctx, rst);
|
||||
|
||||
|
@ -73,23 +73,22 @@ console_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool console_error(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
static bool console_log(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
|
||||
const spidermonkeyFunctionSpec console_funcs[] = {
|
||||
{ "log", console_log, 2 },
|
||||
{ "log", console_log, 1 },
|
||||
{ "error", console_error, 1 },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static bool
|
||||
console_log(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
console_log_common(JSContext *ctx, unsigned int argc, JS::Value *vp, const char *log_filename)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
|
||||
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
if (argc != 1 || !console_log_filename)
|
||||
if (argc != 1 || !log_filename)
|
||||
{
|
||||
args.rval().setBoolean(false);
|
||||
return(true);
|
||||
@ -99,7 +98,7 @@ console_log(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
unsigned char *key = jsval_to_string(ctx, args[0]);
|
||||
|
||||
FILE *f = fopen(console_log_filename, "a");
|
||||
FILE *f = fopen(log_filename, "a");
|
||||
|
||||
if (f)
|
||||
{
|
||||
@ -112,3 +111,21 @@ console_log(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
args.rval().setBoolean(true);
|
||||
return(true);
|
||||
}
|
||||
|
||||
static bool
|
||||
console_log(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
return console_log_common(ctx, argc, vp, console_log_filename);
|
||||
}
|
||||
|
||||
static bool
|
||||
console_error(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
return console_log_common(ctx, argc, vp, console_error_filename);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user