diff --git a/.gitignore b/.gitignore index 49b3073eefbf1f5035d839aaa18754fec0a13d45..b8629cee13886923757d31c1aad1554a0f3af992 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ native/artifacts.json **/.DS_Store *.bk + +*.wot diff --git a/lib/index.js b/lib/index.js index ab3e2715bb150865b1f8e276e66cc6cd2e9f5da6..baa4804451b566191384009f5212dbcbe9f8800d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,3 +1,16 @@ -var addon = require('../native'); +let WebOfTrust = require('../native').WebOfTrust; -console.log(addon.hello()); +{ + let wot = new WebOfTrust(3); + console.log(wot.add_node()); + console.log(wot.size()) +} + +{ + let wot = new WebOfTrust("hey.wot"); + + console.log("Hello, world !"); + console.log(wot.add_node()); + console.log(wot.size()); + console.log(wot.to_file("hey.wot")); +} diff --git a/native/src/lib.rs b/native/src/lib.rs index 0a475ad1eb3f7e3cd452c5854ed05345dc581e7d..e937989a942693ea319b2e6b822cfc25fec3c187 100644 --- a/native/src/lib.rs +++ b/native/src/lib.rs @@ -4,7 +4,7 @@ extern crate neon; extern crate duniter_rs_wotb; -use neon::js::{Value, JsInteger, JsString, JsBoolean, JsFunction, JsArray, JsNumber, Object}; +use neon::js::{Value, JsInteger, JsString, JsBoolean, JsFunction, JsArray, JsNumber, JsObject, Object}; use neon::js::class::{Class, JsClass}; use neon::mem::Handle; use neon::vm::{Throw, Lock}; @@ -19,14 +19,14 @@ declare_types! { let scope = call.scope; let arg0 = try!(call.arguments.require(scope, 0)); - if let Ok(max_cert) = arg0.check::<JsInteger>() { + if let Some(max_cert) = arg0.downcast::<JsInteger>() { let max_cert = max_cert.value(); match max_cert > 0 { true => Ok(WebOfTrust::new(max_cert as usize)), false => Err(Throw), } - } else if let Ok(path) = arg0.check::<JsString>() { + } else if let Some(path) = arg0.downcast::<JsString>() { let path = path.value(); match WebOfTrust::from_file(path.as_str()) {