From 1a022dd1a7547ca65011db70aed75c25e8fb959f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rald=20Hameau?= Date: Sat, 2 Feb 2019 13:02:56 +0100 Subject: [PATCH] Make it compile with node >= 10 --- .gitignore | 5 ++++- nodegsettings.cc | 42 +++++++++++++++++++++--------------------- package.json | 7 ++++--- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index e16a4f1..ca65914 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,7 @@ node_modules/ npm-debug.log *.sublime-* -*~ \ No newline at end of file +*~ + +package-lock.json +.vscode/ \ No newline at end of file diff --git a/nodegsettings.cc b/nodegsettings.cc index ecaeb2a..7495314 100644 --- a/nodegsettings.cc +++ b/nodegsettings.cc @@ -67,7 +67,7 @@ void get_gsetting_keys(const FunctionCallbackInfo& args) { Local togo; togo = Array::New(isolate, size); for (i = 0; keys[i]; i++) { - togo->Set(i,String::NewFromOneByte(isolate, (const uint8_t*) keys[i])); + togo->Set(i, String::NewFromOneByte(isolate, (const uint8_t*) keys[i], NewStringType::kNormal).ToLocalChecked() ); } g_strfreev(keys); args.GetReturnValue().Set(togo); @@ -88,7 +88,7 @@ void get_gsetting(const FunctionCallbackInfo& args) { // validate key and schema GSettingsSchemaSource *schema_source = g_settings_schema_source_get_default(); if ( ! schema_source ) { - isolate->ThrowException(Exception::Error(String::NewFromOneByte(isolate, (const uint8_t*) "No schema source available!"))); + isolate->ThrowException(Exception::Error( String::NewFromOneByte(isolate, (const uint8_t*) "No schema source available!", NewStringType::kNormal ).ToLocalChecked() )); g_free((void *) schema_id); g_free((void *) key); args.GetReturnValue().SetUndefined(); @@ -99,7 +99,7 @@ void get_gsetting(const FunctionCallbackInfo& args) { schema_id, FALSE); if ( ! schema_source ) { - isolate->ThrowException(Exception::Error(String::NewFromOneByte(isolate, (const uint8_t*) "Schema is not installed!"))); + isolate->ThrowException(Exception::Error(String::NewFromOneByte(isolate, (const uint8_t*) "Schema is not installed!", NewStringType::kNormal ).ToLocalChecked() )); g_free((void *) schema_id); g_free((void *) key); args.GetReturnValue().SetUndefined(); @@ -107,7 +107,7 @@ void get_gsetting(const FunctionCallbackInfo& args) { } gboolean has_key = g_settings_schema_has_key (gsettings_schema, key); if ( ! has_key ) { - isolate->ThrowException(Exception::Error(String::NewFromOneByte(isolate, (const uint8_t*) "Key does not exist!"))); + isolate->ThrowException(Exception::Error( String::NewFromOneByte(isolate, (const uint8_t*) "Key does not exist!", NewStringType::kNormal ).ToLocalChecked() )); g_free((void *) schema_id); g_free((void *) key); args.GetReturnValue().SetUndefined(); @@ -198,7 +198,7 @@ void get_gsetting(const FunctionCallbackInfo& args) { return; } else { - isolate->ThrowException(Exception::Error(String::NewFromOneByte(isolate, (const uint8_t*) "Need to implement reading that value type"))); + isolate->ThrowException(Exception::Error( String::NewFromOneByte(isolate, (const uint8_t*) "Need to implement reading that value type", NewStringType::kNormal ).ToLocalChecked() )); args.GetReturnValue().SetUndefined(); return; } @@ -212,7 +212,7 @@ void schema_exists(const FunctionCallbackInfo& args) { if ( ! schema_source ) { g_free(schema_id); - isolate->ThrowException(Exception::Error(String::NewFromOneByte(isolate, (const uint8_t*) "No schema sources available!"))); + isolate->ThrowException(Exception::Error( String::NewFromOneByte(isolate, (const uint8_t*) "No schema sources available!", NewStringType::kNormal ).ToLocalChecked() )); args.GetReturnValue().SetUndefined(); return; } @@ -253,7 +253,7 @@ void set_gsetting(const FunctionCallbackInfo& args) { if ( ! schema_source ) { g_free((void *) schema_id); g_free((void *) key); - isolate->ThrowException(Exception::Error(String::NewFromOneByte(isolate, (const uint8_t*) "No schema source available!"))); + isolate->ThrowException(Exception::Error( String::NewFromOneByte(isolate, (const uint8_t*) "No schema source available!", NewStringType::kNormal).ToLocalChecked() )); args.GetReturnValue().SetUndefined(); return; } @@ -264,7 +264,7 @@ void set_gsetting(const FunctionCallbackInfo& args) { if ( ! schema_source ) { g_free((void *) schema_id); g_free((void *) key); - isolate->ThrowException(Exception::Error(String::NewFromOneByte(isolate, (const uint8_t*) "Schema is not installed!"))); + isolate->ThrowException(Exception::Error( String::NewFromOneByte(isolate, (const uint8_t*) "Schema is not installed!", NewStringType::kNormal).ToLocalChecked() )); args.GetReturnValue().SetUndefined(); return; } @@ -272,7 +272,7 @@ void set_gsetting(const FunctionCallbackInfo& args) { if ( ! has_key ) { g_free((void *) schema_id); g_free((void *) key); - isolate->ThrowException(Exception::Error(String::NewFromOneByte(isolate, (const uint8_t*) "Key does not exist!"))); + isolate->ThrowException(Exception::Error( String::NewFromOneByte(isolate, (const uint8_t*) "Key does not exist!", NewStringType::kNormal).ToLocalChecked() )); args.GetReturnValue().SetUndefined(); return; } @@ -307,7 +307,7 @@ void set_gsetting(const FunctionCallbackInfo& args) { else if ( g_variant_type_equal(type, G_VARIANT_TYPE_DOUBLE) ) { if ( value_obj->IsNumber() ) { validation_success = true; - variant_to_set = g_variant_new_double(value_obj->ToNumber()->Value()); + variant_to_set = g_variant_new_double(value_obj->ToNumber(isolate)->Value()); } else { validation_fail_message = "Key requires a number!"; } @@ -315,7 +315,7 @@ void set_gsetting(const FunctionCallbackInfo& args) { else if ( g_variant_type_equal(type, G_VARIANT_TYPE_INT32) ) { if ( value_obj->IsInt32() ) { validation_success = true; - variant_to_set = g_variant_new_int32 (value_obj->ToInt32()->Value()); + variant_to_set = g_variant_new_int32 (value_obj->ToInt32(isolate)->Value()); } else { validation_fail_message = "Key requires a integer number!"; } @@ -323,7 +323,7 @@ void set_gsetting(const FunctionCallbackInfo& args) { else if ( g_variant_type_equal(type, G_VARIANT_TYPE_UINT32) ) { if ( value_obj->IsUint32() ) { validation_success = true; - variant_to_set = g_variant_new_uint32(value_obj->ToUint32()->Value()); + variant_to_set = g_variant_new_uint32( value_obj->ToUint32( isolate->GetCurrentContext() ).ToLocalChecked()->Value() ); } else { validation_fail_message = "Key requires a unsigned integer number!"; } @@ -337,7 +337,7 @@ void set_gsetting(const FunctionCallbackInfo& args) { Local obj = value_obj->ToObject(); // get the array length - length = obj->Get(String::NewFromOneByte(isolate, (const uint8_t*) "length"))->ToObject()->Uint32Value(); + length = obj->Get(String::NewFromOneByte(isolate, (const uint8_t*) "length", NewStringType::kNormal).ToLocalChecked())->ToObject()->Uint32Value(); g_variant_builder_init (&builder, G_VARIANT_TYPE_STRING_ARRAY); @@ -354,7 +354,7 @@ void set_gsetting(const FunctionCallbackInfo& args) { } else { g_free((void *) key); - isolate->ThrowException(Exception::Error(String::NewFromOneByte(isolate, (const uint8_t*) "Array item have to be strings!"))); + isolate->ThrowException(Exception::Error(String::NewFromOneByte(isolate, (const uint8_t*) "Array item have to be strings!", NewStringType::kNormal).ToLocalChecked())); args.GetReturnValue().SetUndefined(); return; } @@ -371,7 +371,7 @@ void set_gsetting(const FunctionCallbackInfo& args) { if ( ! validation_success ) { g_free((void *) key); - isolate->ThrowException(Exception::Error(String::NewFromOneByte(isolate, (const uint8_t*) validation_fail_message))); + isolate->ThrowException(Exception::Error(String::NewFromOneByte(isolate, (const uint8_t*) validation_fail_message, NewStringType::kNormal).ToLocalChecked())); args.GetReturnValue().SetUndefined(); return; } @@ -381,7 +381,7 @@ void set_gsetting(const FunctionCallbackInfo& args) { if ( ! is_valid ) { g_free((void *) key); - isolate->ThrowException(Exception::Error(String::NewFromOneByte(isolate, (const uint8_t*) "Invalid range or type!"))); + isolate->ThrowException(Exception::Error(String::NewFromOneByte(isolate, (const uint8_t*) "Invalid range or type!", NewStringType::kNormal).ToLocalChecked())); args.GetReturnValue().SetUndefined(); return; } @@ -393,7 +393,7 @@ void set_gsetting(const FunctionCallbackInfo& args) { g_free((void *) key); if ( ! write_success ) { - isolate->ThrowException(Exception::Error(String::NewFromOneByte(isolate, (const uint8_t*) "Failed to set gsetting! Key is write protected."))); + isolate->ThrowException(Exception::Error(String::NewFromOneByte(isolate, (const uint8_t*) "Failed to set gsetting! Key is write protected.", NewStringType::kNormal).ToLocalChecked())); } args.GetReturnValue().SetUndefined(); @@ -404,13 +404,13 @@ void set_gsetting(const FunctionCallbackInfo& args) { void init(Local target) { Isolate *isolate = target->GetIsolate(); - target->Set(String::NewFromOneByte(isolate, (const uint8_t*) "set_gsetting"), + target->Set(String::NewFromOneByte(isolate, (const uint8_t*) "set_gsetting", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, set_gsetting)->GetFunction()); - target->Set(String::NewFromOneByte(isolate, (const uint8_t*) "get_gsetting"), + target->Set(String::NewFromOneByte(isolate, (const uint8_t*) "get_gsetting", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, get_gsetting)->GetFunction()); - target->Set(String::NewFromOneByte(isolate, (const uint8_t*) "get_gsetting_keys"), + target->Set(String::NewFromOneByte(isolate, (const uint8_t*) "get_gsetting_keys", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, get_gsetting_keys)->GetFunction()); - target->Set(String::NewFromOneByte(isolate, (const uint8_t*) "schema_exists"), + target->Set(String::NewFromOneByte(isolate, (const uint8_t*) "schema_exists", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, schema_exists)->GetFunction()); } diff --git a/package.json b/package.json index ff52972..72bb214 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "node-gsettings", "description": "Node binding to gsettings dconf tool", - "version": "0.1.9", + "version": "0.1.10", "author": "Leopold Burdyl", "scripts": { "test": "node tests/test.js" @@ -28,9 +28,10 @@ "repository": "https://github.com/vilnius-leopold/node-gsettings.git", "main": "index.js", "engines": { - "node": ">=0.1.9" + "node": ">=10.0" }, "devDependencies": { - "truncate": "^1.0.4" + "truncate": "^1.0.4", + "eslint": "^5.13.0" } }