From 348d2ac4903ee541bd756c641207fb52409e5054 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sun, 30 Jan 2022 12:48:21 +0100 Subject: [PATCH] [quickjs] localstorage const --- src/ecmascript/localstorage-db.c | 16 +++++------ src/ecmascript/localstorage-db.h | 10 +++---- src/ecmascript/quickjs/localstorage.c | 39 +++++---------------------- 3 files changed, 20 insertions(+), 45 deletions(-) diff --git a/src/ecmascript/localstorage-db.c b/src/ecmascript/localstorage-db.c index bfb2511df..e07deda6a 100644 --- a/src/ecmascript/localstorage-db.c +++ b/src/ecmascript/localstorage-db.c @@ -36,7 +36,7 @@ db_prepare_structure(char *db_name) } int -db_delete_from(char *db_name, char *key) +db_delete_from(char *db_name, const char *key) { sqlite3_stmt *stmt; @@ -65,7 +65,7 @@ db_delete_from(char *db_name, char *key) int -db_insert_into(char *db_name, char *key, char *value) +db_insert_into(char *db_name, const char *key, const char *value) { sqlite3_stmt *stmt; sqlite3 *db; @@ -92,7 +92,7 @@ db_insert_into(char *db_name, char *key, char *value) } int -db_update_set(char *db_name, char *key, char *value) +db_update_set(char *db_name, const char *key, const char *value) { sqlite3_stmt *stmt; @@ -120,7 +120,7 @@ db_update_set(char *db_name, char *key, char *value) } char * -db_query_by_value(char *db_name, char *value) +db_query_by_value(char *db_name, const char *value) { sqlite3_stmt *stmt; @@ -140,7 +140,7 @@ db_query_by_value(char *db_name, char *value) rc=sqlite3_prepare_v2(db, "SELECT key FROM storage WHERE value = ? LIMIT 1;", -1, &stmt, NULL); rc=sqlite3_bind_text(stmt, 1, value, strlen(value), SQLITE_STATIC); - if ((const char*) sqlite3_column_text(stmt,1)!= NULL) { + if (sqlite3_column_text(stmt,1)!= NULL) { result=stracpy((const char *)sqlite3_column_text(stmt, 1)); } else { result=stracpy(""); @@ -152,7 +152,7 @@ db_query_by_value(char *db_name, char *value) } char * -db_query_by_key(char *db_name, char *key) +db_query_by_key(char *db_name, const char *key) { sqlite3_stmt *stmt; @@ -172,8 +172,8 @@ db_query_by_key(char *db_name, char *key) rc=sqlite3_prepare_v2(db, "SELECT * FROM storage WHERE key = ? LIMIT 1;", -1, &stmt, NULL); rc=sqlite3_bind_text(stmt, 1, key, strlen(key), SQLITE_STATIC); rc=sqlite3_step(stmt); - if ((const char*) sqlite3_column_text(stmt,1)!= NULL) { - result=stracpy((const unsigned char *)sqlite3_column_text(stmt, 1)); + if (sqlite3_column_text(stmt,1)!= NULL) { + result=stracpy((const char *)sqlite3_column_text(stmt, 1)); } else { result = nullptr; } diff --git a/src/ecmascript/localstorage-db.h b/src/ecmascript/localstorage-db.h index ec4ca66aa..6a670c7c5 100644 --- a/src/ecmascript/localstorage-db.h +++ b/src/ecmascript/localstorage-db.h @@ -7,10 +7,10 @@ #include int db_prepare_structure(char *db_name); -int db_delete_from(char *db_name, char *key); -int db_insert_into(char *db_name, char *key, char *value); -int db_update_set(char *db_name, char *key, char *value); -char * db_query_by_key(char *db_name, char *key); -char * db_qry_by_value(char *db_name, char *val); +int db_delete_from(char *db_name, const char *key); +int db_insert_into(char *db_name, const char *key, const char *value); +int db_update_set(char *db_name, const char *key, const char *value); +char * db_query_by_key(char *db_name, const char *key); +char * db_qry_by_value(char *db_name, const char *val); #endif diff --git a/src/ecmascript/quickjs/localstorage.c b/src/ecmascript/quickjs/localstorage.c index 135ef0043..9428263a9 100644 --- a/src/ecmascript/quickjs/localstorage.c +++ b/src/ecmascript/quickjs/localstorage.c @@ -54,11 +54,11 @@ static JSClassID js_localstorage_class_id; /* IMPLEMENTS READ FROM STORAGE USING SQLITE DATABASE */ -static unsigned char * -readFromStorage(const unsigned char *key) +static char * +readFromStorage(const char *key) { - char * val; + char *val; if (local_storage_ready==0) { @@ -70,11 +70,11 @@ readFromStorage(const unsigned char *key) //DBG("Read: %s %s %s",local_storage_filename, key, val); - return (val); + return val; } static void -removeFromStorage(const unsigned char *key) +removeFromStorage(const char *key) { if (local_storage_ready==0) { @@ -86,7 +86,7 @@ removeFromStorage(const unsigned char *key) /* IMPLEMENTS SAVE TO STORAGE USING SQLITE DATABASE */ static void -saveToStorage(const unsigned char *key, const unsigned char *val) +saveToStorage(const char *key, const char *val) { if (local_storage_ready==0) { db_prepare_structure(local_storage_filename); @@ -125,7 +125,7 @@ js_localstorage_getitem(JSContext *ctx, JSValueConst this_val, int argc, JSValue return JS_EXCEPTION; } - unsigned char *val = readFromStorage(key); + char *val = readFromStorage(key); JS_FreeCString(ctx, key); if (!val) { @@ -224,31 +224,6 @@ static JSClassDef js_localstorage_class = { "localStorage", }; -static JSValue -js_localstorage_ctor(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv) -{ - JSValue obj = JS_UNDEFINED; - JSValue proto; - /* using new_target to get the prototype is necessary when the - class is extended. */ - proto = JS_GetPropertyStr(ctx, new_target, "prototype"); - - if (JS_IsException(proto)) { - goto fail; - } - obj = JS_NewObjectProtoClass(ctx, proto, js_localstorage_class_id); - JS_FreeValue(ctx, proto); - - if (JS_IsException(obj)) { - goto fail; - } - RETURN_JS(obj); - -fail: - JS_FreeValue(ctx, obj); - return JS_EXCEPTION; -} - int js_localstorage_init(JSContext *ctx) {