Commit 4e093a26 authored by nanocryk's avatar nanocryk
Browse files

feature : working calls from nodejs

parent 9b6b9846
......@@ -6,3 +6,5 @@ native/artifacts.json
**/.DS_Store
*.bk
*.wot
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"));
}
......@@ -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()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment