Commit cf7477c3 authored by legoc's avatar legoc
Browse files

Updated addons

parent 2f2ea51e
......@@ -16,6 +16,7 @@ namespace nomad {
using v8::Function;
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Context;
using v8::Local;
using v8::Object;
using v8::String;
......@@ -28,6 +29,7 @@ using v8::Persistent;
NomadAccessor accessor;
Isolate * v8Isolate;
v8::Local<v8::Context> context;
/**
* Init function to initialise the Cameo Nomad addon.
......@@ -38,21 +40,21 @@ void Init(const FunctionCallbackInfo<Value>& args) {
v8Isolate = args.GetIsolate();
// Local endpoint.
v8::String::Utf8Value param1(args[0]->ToString());
v8::String::Utf8Value param1(v8Isolate, args[0]);
string localEndpoint(*param1);
// Initialise the Nomad accessor.
accessor.init("vEXP", localEndpoint);
// Nomad endpoint.
v8::String::Utf8Value param2(args[1]->ToString());
v8::String::Utf8Value param2(v8Isolate, args[1]);
string nomadEndpoint(*param2);
// Connect to a nomad sim depending on the size of the args.
if (args.Length() > 2) {
// Interpret the arg 2 in string because it comes from the command line and is not a V8 integer.
v8::String::Utf8Value param3(args[3]->ToString());
v8::String::Utf8Value param3(v8Isolate, args[3]);
string arg3(*param3);
istringstream is(arg3);
......@@ -83,10 +85,10 @@ void Terminate(const FunctionCallbackInfo<Value>& args) {
*/
void GetPropertyId(const FunctionCallbackInfo<Value>& args) {
v8::String::Utf8Value param0(args[0]->ToString());
v8::String::Utf8Value param0(v8Isolate, args[0]);
std::string servantName(*param0);
v8::String::Utf8Value param1(args[1]->ToString());
v8::String::Utf8Value param1(v8Isolate, args[1]);
std::string propertyName(*param1);
args.GetReturnValue().Set(Number::New(args.GetIsolate(), accessor.getPropertyId(servantName, propertyName)));
......@@ -119,7 +121,7 @@ void GetBooleanProperty(const FunctionCallbackInfo<Value>& args) {
void GetStringProperty(const FunctionCallbackInfo<Value>& args) {
string value = accessor.getStringValue(Local<Integer>::Cast(args[0])->Value());
args.GetReturnValue().Set(String::NewFromUtf8(args.GetIsolate(), value.c_str()));
args.GetReturnValue().Set(String::NewFromUtf8(args.GetIsolate(), value.c_str()).ToLocalChecked());
}
/**
......@@ -127,12 +129,13 @@ void GetStringProperty(const FunctionCallbackInfo<Value>& args) {
*/
void GetInt32ArrayProperty(const FunctionCallbackInfo<Value>& args) {
Local<Context> context = args.GetIsolate()->GetCurrentContext();
Local<Array> array = Array::New(args.GetIsolate(), 0);
vector<int32_t> arrayValue = accessor.getInt32Array(Local<Integer>::Cast(args[0])->Value());
for (int i = 0; i < arrayValue.size(); ++i) {
array->Set(i, Integer::New(args.GetIsolate(), arrayValue[i]));
array->Set(context, i, Integer::New(args.GetIsolate(), arrayValue[i]));
}
args.GetReturnValue().Set(array);
......@@ -143,12 +146,13 @@ void GetInt32ArrayProperty(const FunctionCallbackInfo<Value>& args) {
*/
void GetFloat64ArrayProperty(const FunctionCallbackInfo<Value>& args) {
Local<Context> context = args.GetIsolate()->GetCurrentContext();
Local<Array> array = Array::New(args.GetIsolate(), 0);
vector<double> arrayValue = accessor.getFloat64Array(Local<Integer>::Cast(args[0])->Value());
for (int i = 0; i < arrayValue.size(); ++i) {
array->Set(i, Number::New(args.GetIsolate(), arrayValue[i]));
array->Set(context, i, Number::New(args.GetIsolate(), arrayValue[i]));
}
args.GetReturnValue().Set(array);
......@@ -179,7 +183,7 @@ void SetBooleanProperty(const FunctionCallbackInfo<Value>& args) {
* Sets the string property value.
*/
void SetStringProperty(const FunctionCallbackInfo<Value>& args) {
v8::String::Utf8Value param1(args[1]->ToString());
v8::String::Utf8Value param1(v8Isolate, args[1]);
std::string value(*param1);
args.GetReturnValue().Set(Boolean::New(args.GetIsolate(), accessor.setStringValue(Local<Integer>::Cast(args[0])->Value(), value)));
}
......@@ -205,7 +209,7 @@ static void WorkAsync(uv_work_t *req) {
*/
template<typename Type, typename JSType>
static void WorkAsyncComplete(uv_work_t *req, int status) {
/*
Isolate * isolate = Isolate::GetCurrent();
v8::HandleScope handleScope(isolate);
......@@ -219,7 +223,7 @@ static void WorkAsyncComplete(uv_work_t *req, int status) {
Local<Function>::New(isolate, work->callback)->Call(isolate->GetCurrentContext()->Global(), 1, argv);
work->callback.Reset();
delete work;
delete work;*/
}
/**
......@@ -228,7 +232,7 @@ static void WorkAsyncComplete(uv_work_t *req, int status) {
*/
static void StringWorkAsyncComplete(uv_work_t *req, int status) {
Isolate * isolate = Isolate::GetCurrent();
/* Isolate * isolate = Isolate::GetCurrent();
v8::HandleScope handleScope(isolate);
......@@ -241,7 +245,7 @@ static void StringWorkAsyncComplete(uv_work_t *req, int status) {
Local<Function>::New(isolate, work->callback)->Call(isolate->GetCurrentContext()->Global(), 1, argv);
work->callback.Reset();
delete work;
delete work;*/
}
/**
......@@ -249,7 +253,7 @@ static void StringWorkAsyncComplete(uv_work_t *req, int status) {
* function in JS.
*/
static void Float64ArrayWorkAsyncComplete(uv_work_t *req, int status) {
/*
Isolate * isolate = Isolate::GetCurrent();
v8::HandleScope handleScope(isolate);
......@@ -271,7 +275,7 @@ static void Float64ArrayWorkAsyncComplete(uv_work_t *req, int status) {
Local<Function>::New(isolate, work->callback)->Call(isolate->GetCurrentContext()->Global(), 1, argv);
work->callback.Reset();
delete work;
delete work;*/
}
/**
......@@ -279,7 +283,7 @@ static void Float64ArrayWorkAsyncComplete(uv_work_t *req, int status) {
* function in JS.
*/
static void Int32ArrayWorkAsyncComplete(uv_work_t *req, int status) {
/*
Isolate * isolate = Isolate::GetCurrent();
v8::HandleScope handleScope(isolate);
......@@ -301,56 +305,56 @@ static void Int32ArrayWorkAsyncComplete(uv_work_t *req, int status) {
Local<Function>::New(isolate, work->callback)->Call(isolate->GetCurrentContext()->Global(), 1, argv);
work->callback.Reset();
delete work;
delete work;*/
}
template<typename Type, typename JSType>
void PropertyChanged(Persistent<Function>* callback, Type value) {
/*
Work<Type> * work = new Work<Type>();
work->request.data = work;
work->callback.Reset(v8Isolate, *callback);
work->result = value;
uv_queue_work(uv_default_loop(), &work->request, WorkAsync, WorkAsyncComplete<Type, JSType>);
uv_queue_work(uv_default_loop(), &work->request, WorkAsync, WorkAsyncComplete<Type, JSType>);*/
}
void StringPropertyChanged(Persistent<Function>* callback, const std::string& value) {
/*
Work<string> * work = new Work<string>();
work->request.data = work;
work->callback.Reset(v8Isolate, *callback);
work->result = value;
uv_queue_work(uv_default_loop(), &work->request, WorkAsync, StringWorkAsyncComplete);
uv_queue_work(uv_default_loop(), &work->request, WorkAsync, StringWorkAsyncComplete);*/
}
void Float64ArrayPropertyChanged(Persistent<Function>* callback, const std::vector<double>& value) {
/*
Work<std::vector<double> > * work = new Work<std::vector<double> >();
work->request.data = work;
work->callback.Reset(v8Isolate, *callback);
work->result = value;
uv_queue_work(uv_default_loop(), &work->request, WorkAsync, Float64ArrayWorkAsyncComplete);
uv_queue_work(uv_default_loop(), &work->request, WorkAsync, Float64ArrayWorkAsyncComplete);*/
}
void Int32ArrayPropertyChanged(Persistent<Function>* callback, const std::vector<int32_t>& value) {
/*
Work<std::vector<int32_t> > * work = new Work<std::vector<int32_t> >();
work->request.data = work;
work->callback.Reset(v8Isolate, *callback);
work->result = value;
uv_queue_work(uv_default_loop(), &work->request, WorkAsync, Int32ArrayWorkAsyncComplete);
uv_queue_work(uv_default_loop(), &work->request, WorkAsync, Int32ArrayWorkAsyncComplete);*/
}
void RegisterFloat64PropertyChanged(const FunctionCallbackInfo<Value>& args) {
/*
Isolate * isolate = args.GetIsolate();
int propertyId = Local<Integer>::Cast(args[0])->Value();
......@@ -362,11 +366,11 @@ void RegisterFloat64PropertyChanged(const FunctionCallbackInfo<Value>& args) {
pCallback->Reset(isolate, callback);
accessor.registerFloat64PropertyChanged(propertyId, std::bind(&PropertyChanged<double, Number>, pCallback, _1));
args.GetReturnValue().Set(Undefined(isolate));
args.GetReturnValue().Set(Undefined(isolate));*/
}
void RegisterInt32PropertyChanged(const FunctionCallbackInfo<Value>& args) {
/*
Isolate * isolate = args.GetIsolate();
int propertyId = Local<Integer>::Cast(args[0])->Value();
......@@ -378,11 +382,11 @@ void RegisterInt32PropertyChanged(const FunctionCallbackInfo<Value>& args) {
pCallback->Reset(isolate, callback);
accessor.registerInt32PropertyChanged(propertyId, std::bind(&PropertyChanged<int32_t, Integer>, pCallback, _1));
args.GetReturnValue().Set(Undefined(isolate));
args.GetReturnValue().Set(Undefined(isolate));*/
}
void RegisterBooleanPropertyChanged(const FunctionCallbackInfo<Value>& args) {
/*
Isolate * isolate = args.GetIsolate();
int propertyId = Local<Integer>::Cast(args[0])->Value();
......@@ -394,11 +398,11 @@ void RegisterBooleanPropertyChanged(const FunctionCallbackInfo<Value>& args) {
pCallback->Reset(isolate, callback);
accessor.registerBooleanPropertyChanged(propertyId, std::bind(&PropertyChanged<bool, Boolean>, pCallback, _1));
args.GetReturnValue().Set(Undefined(isolate));
args.GetReturnValue().Set(Undefined(isolate));*/
}
void RegisterStringPropertyChanged(const FunctionCallbackInfo<Value>& args) {
/*
Isolate * isolate = args.GetIsolate();
int propertyId = Local<Integer>::Cast(args[0])->Value();
......@@ -410,11 +414,11 @@ void RegisterStringPropertyChanged(const FunctionCallbackInfo<Value>& args) {
pCallback->Reset(isolate, callback);
accessor.registerStringPropertyChanged(propertyId, std::bind(&StringPropertyChanged, pCallback, _1));
args.GetReturnValue().Set(Undefined(isolate));
args.GetReturnValue().Set(Undefined(isolate));*/
}
void RegisterFloat64ArrayPropertyChanged(const FunctionCallbackInfo<Value>& args) {
/*
Isolate * isolate = args.GetIsolate();
int propertyId = Local<Integer>::Cast(args[0])->Value();
......@@ -426,11 +430,11 @@ void RegisterFloat64ArrayPropertyChanged(const FunctionCallbackInfo<Value>& args
pCallback->Reset(isolate, callback);
accessor.registerFloat64ArrayPropertyChanged(propertyId, std::bind(&Float64ArrayPropertyChanged, pCallback, _1));
args.GetReturnValue().Set(Undefined(isolate));
args.GetReturnValue().Set(Undefined(isolate));*/
}
void RegisterInt32ArrayPropertyChanged(const FunctionCallbackInfo<Value>& args) {
/*
Isolate * isolate = args.GetIsolate();
int propertyId = Local<Integer>::Cast(args[0])->Value();
......@@ -442,7 +446,7 @@ void RegisterInt32ArrayPropertyChanged(const FunctionCallbackInfo<Value>& args)
pCallback->Reset(isolate, callback);
accessor.registerInt32ArrayPropertyChanged(propertyId, std::bind(&Int32ArrayPropertyChanged, pCallback, _1));
args.GetReturnValue().Set(Undefined(isolate));
args.GetReturnValue().Set(Undefined(isolate));*/
}
/**
......
......@@ -47,11 +47,11 @@ void Init(const FunctionCallbackInfo<Value>& args) {
v8Isolate = args.GetIsolate();
// Local endpoint.
v8::String::Utf8Value param1(args[0]->ToString());
v8::String::Utf8Value param1(v8Isolate, args[0]);
string localEndpoint(*param1);
// Nomad endpoint.
v8::String::Utf8Value param2(args[1]->ToString());
v8::String::Utf8Value param2(v8Isolate, args[1]);
string nomadEndpoint(*param2);
// Init the app if it is not already done.
......@@ -112,7 +112,7 @@ void GetData(const FunctionCallbackInfo<Value>& args) {
string response;
requester->receive(response);
args.GetReturnValue().Set(String::NewFromUtf8(args.GetIsolate(), response.c_str()));
args.GetReturnValue().Set(String::NewFromUtf8(args.GetIsolate(), response.c_str()).ToLocalChecked());
}
/**
......
......@@ -18,6 +18,7 @@ using v8::Integer;
using v8::Boolean;
using v8::Array;
using v8::Persistent;
using v8::Context;
// the native vexp library
......@@ -36,7 +37,7 @@ void createSqwTree(const FunctionCallbackInfo<Value>& args) {
if(args.Length() != 0) {
auto str = String::NewFromUtf8(iso, "createSqwTree takes no arguments");
iso->ThrowException(Exception::TypeError(str));
iso->ThrowException(Exception::TypeError(str.ToLocalChecked()));
return;
}
......@@ -53,11 +54,11 @@ void removeSqwTree(const FunctionCallbackInfo<Value>& args) {
if(args.Length() != 1 || !args[0]->IsInt32()) {
auto str = String::NewFromUtf8(iso, "removeSqwTree takes one argument: the tree handle");
iso->ThrowException(Exception::TypeError(str));
iso->ThrowException(Exception::TypeError(str.ToLocalChecked()));
return;
}
int handle = args[0]->Int32Value();
int handle = Local<Integer>::Cast(args[0])->Value();
accessor.removeSqwTree(handle);
}
......@@ -70,11 +71,11 @@ void clearSqwTree(const FunctionCallbackInfo<Value>& args) {
if(args.Length() != 1 || !args[0]->IsInt32()) {
auto str = String::NewFromUtf8(iso, "clearSqwTree takes one argument: the tree handle");
iso->ThrowException(Exception::TypeError(str));
iso->ThrowException(Exception::TypeError(str.ToLocalChecked()));
return;
}
int handle = args[0]->Int32Value();
int handle = Local<Integer>::Cast(args[0])->Value();
accessor.clearSqwTree(handle);
}
......@@ -88,17 +89,17 @@ void addSqwValue(const FunctionCallbackInfo<Value>& args) {
if(args.Length() != 6 || !args[0]->IsInt32() ||
!args[1]->IsNumber() || !args[2]->IsNumber() || !args[3]->IsNumber() || !args[4]->IsNumber() || !args[5]->IsNumber()) {
auto str = String::NewFromUtf8(iso, "addSqwValue takes six arguments: the tree handle and h, k, l, E, S");
iso->ThrowException(Exception::TypeError(str));
iso->ThrowException(Exception::TypeError(str.ToLocalChecked()));
return;
}
int handle = args[0]->Int32Value();
int handle = Local<Integer>::Cast(args[0])->Value();
double h = args[1]->NumberValue();
double k = args[2]->NumberValue();
double l = args[3]->NumberValue();
double E = args[4]->NumberValue();
double S = args[5]->NumberValue();
double h = Local<Number>::Cast(args[1])->Value();
double k = Local<Number>::Cast(args[2])->Value();
double l = Local<Number>::Cast(args[3])->Value();
double E = Local<Number>::Cast(args[4])->Value();
double S = Local<Number>::Cast(args[5])->Value();
accessor.addSqwValue(handle, h, k, l, E, S);
}
......@@ -112,14 +113,15 @@ void loadSqwTable(const FunctionCallbackInfo<Value>& args) {
if(args.Length() != 2 || !args[0]->IsInt32() || !args[1]->IsString()) {
auto str = String::NewFromUtf8(iso, "loadSqwTable takes two arguments: the tree handle and the file name");
iso->ThrowException(Exception::TypeError(str));
iso->ThrowException(Exception::TypeError(str.ToLocalChecked()));
return;
}
int handle = args[0]->Int32Value();
int handle = Local<Integer>::Cast(args[0])->Value();
auto str = args[1]->ToString();
int len = str->Utf8Length();
Local<String> str = Local<String>::Cast(args[1]);
int len = str->Utf8Length(iso);
if(len < 0) {
std::cerr << "Invalid string argument in loadSqwTable!" << std::endl;
args.GetReturnValue().Set(Boolean::New(iso, false));
......@@ -128,7 +130,7 @@ void loadSqwTable(const FunctionCallbackInfo<Value>& args) {
char *file = new char[len+1];
file[len] = 0;
str->WriteUtf8(file, len+1);
str->WriteUtf8(iso, file, len+1);
//const char *file = *String::Utf8Value(iso, args[1]);
......@@ -145,30 +147,31 @@ void loadSqwTable(const FunctionCallbackInfo<Value>& args) {
*/
void querySqwTree(const FunctionCallbackInfo<Value>& args) {
auto *iso = args.GetIsolate();
Local<Context> context = iso->GetCurrentContext();
if(args.Length() != 5 || !args[0]->IsInt32() ||
!args[1]->IsNumber() || !args[2]->IsNumber() || !args[3]->IsNumber() || !args[4]->IsNumber()) {
auto str = String::NewFromUtf8(iso, "querySqwTree takes five arguments: the tree handle and the h, k, l, E coordinates");
iso->ThrowException(Exception::TypeError(str));
iso->ThrowException(Exception::TypeError(str.ToLocalChecked()));
return;
}
int handle = args[0]->Int32Value();
double h = args[1]->NumberValue();
double k = args[2]->NumberValue();
double l = args[3]->NumberValue();
double E = args[4]->NumberValue();
int handle = Local<Integer>::Cast(args[0])->Value();
double h = Local<Number>::Cast(args[1])->Value();
double k = Local<Number>::Cast(args[2])->Value();
double l = Local<Number>::Cast(args[3])->Value();
double E = Local<Number>::Cast(args[4])->Value();
double S = 0;
bool bOk = accessor.querySqwTree(handle, h, k, l, E, S);
auto result = Object::New(iso);
result->Set(String::NewFromUtf8(iso, "ok"), Boolean::New(iso, bOk));
result->Set(String::NewFromUtf8(iso, "h"), Number::New(iso, h));
result->Set(String::NewFromUtf8(iso, "k"), Number::New(iso, k));
result->Set(String::NewFromUtf8(iso, "l"), Number::New(iso, l));
result->Set(String::NewFromUtf8(iso, "E"), Number::New(iso, E));
result->Set(String::NewFromUtf8(iso, "S"), Number::New(iso, S));
result->Set(context, String::NewFromUtf8(iso, "ok").ToLocalChecked(), Boolean::New(iso, bOk));
result->Set(context, String::NewFromUtf8(iso, "h").ToLocalChecked(), Number::New(iso, h));
result->Set(context, String::NewFromUtf8(iso, "k").ToLocalChecked(), Number::New(iso, k));
result->Set(context, String::NewFromUtf8(iso, "l").ToLocalChecked(), Number::New(iso, l));
result->Set(context, String::NewFromUtf8(iso, "E").ToLocalChecked(), Number::New(iso, E));
result->Set(context, String::NewFromUtf8(iso, "S").ToLocalChecked(), Number::New(iso, S));
args.GetReturnValue().Set(result);
}
......@@ -188,7 +191,7 @@ void createCIF(const FunctionCallbackInfo<Value>& args) {
if(args.Length() != 0) {
auto str = String::NewFromUtf8(iso, "createCIF takes no arguments");
iso->ThrowException(Exception::TypeError(str));
iso->ThrowException(Exception::TypeError(str.ToLocalChecked()));
return;
}
......@@ -205,11 +208,11 @@ void removeCIF(const FunctionCallbackInfo<Value>& args) {
if(args.Length() != 1 || !args[0]->IsInt32()) {
auto str = String::NewFromUtf8(iso, "removeCIF takes one argument: the CIF handle");
iso->ThrowException(Exception::TypeError(str));
iso->ThrowException(Exception::TypeError(str.ToLocalChecked()));
return;
}
int handle = args[0]->Int32Value();
int handle = Local<Integer>::Cast(args[0])->Value();
accessor.removeCIF(handle);
}
......@@ -222,11 +225,11 @@ void clearCIF(const FunctionCallbackInfo<Value>& args) {
if(args.Length() != 1 || !args[0]->IsInt32()) {
auto str = String::NewFromUtf8(iso, "clearCIF takes one argument: the CIF handle");
iso->ThrowException(Exception::TypeError(str));
iso->ThrowException(Exception::TypeError(str.ToLocalChecked()));
return;
}
int handle = args[0]->Int32Value();
int handle = Local<Integer>::Cast(args[0])->Value();
accessor.clearCIF(handle);
}
......@@ -239,14 +242,15 @@ void loadCIF(const FunctionCallbackInfo<Value>& args) {
if(args.Length() != 3 || !args[0]->IsInt32() || !args[1]->IsString() || !args[2]->IsBoolean()) {
auto str = String::NewFromUtf8(iso, "loadCIF takes three arguments: the CIF handle, the file name or data string, and a boolean");
iso->ThrowException(Exception::TypeError(str));
iso->ThrowException(Exception::TypeError(str.ToLocalChecked()));
return;
}
int handle = args[0]->Int32Value();
int handle = Local<Integer>::Cast(args[0])->Value();
Local<String> str = Local<String>::Cast(args[1]);
auto str = args[1]->ToString();
int len = str->Utf8Length();
int len = str->Utf8Length(iso);
if(len < 0) {
std::cerr << "Invalid string argument in loadCIF!" << std::endl;
args.GetReturnValue().Set(Boolean::New(iso, false));
......@@ -255,10 +259,10 @@ void loadCIF(const FunctionCallbackInfo<Value>& args) {
char *file = new char[len+1];
file[len] = 0;
str->WriteUtf8(file, len+1);
str->WriteUtf8(iso, file, len+1);
//const char* file = *String::Utf8Value(iso, args[1]->ToString());
bool is_file = args[2]->BooleanValue();
bool is_file = Local<Boolean>::Cast(args[2])->Value();
//const char* file = "/Users/tw/tmp/mnsi.cif";
//bool is_file = true;
......@@ -275,27 +279,28 @@ void loadCIF(const FunctionCallbackInfo<Value>& args) {
*/
void getCIFLattice(const FunctionCallbackInfo<Value>& args) {
auto *iso = args.GetIsolate();
Local<Context> context = iso->GetCurrentContext();
if(args.Length() != 1 || !args[0]->IsInt32()) {
auto str = String::NewFromUtf8(iso, "getCIFLattice takes one argument: the CIF handle");
iso->ThrowException(Exception::TypeError(str));
iso->ThrowException(Exception::TypeError(str.ToLocalChecked()));
return;
}
int handle = args[0]->Int32Value();
int handle = Local<Integer>::Cast(args[0])->Value();
double a=0, b=0, c=0;
double alpha=0, beta=0, gamma=0;
bool bOk = accessor.getCIFLattice(handle, a, b, c, alpha, beta, gamma);
auto result = Object::New(iso);
result->Set(String::NewFromUtf8(iso, "ok"), Boolean::New(iso, bOk));
result->Set(String::NewFromUtf8(iso, "a"), Number::New(iso, a));
result->Set(String::NewFromUtf8(iso, "b"), Number::New(iso, b));
result->Set(String::NewFromUtf8(iso, "c"), Number::New(iso, c));
result->Set(String::NewFromUtf8(iso, "alpha"), Number::New(iso, alpha));
result->Set(String::NewFromUtf8(iso, "beta"), Number::New(iso, beta));
result->Set(String::NewFromUtf8(iso, "gamma"), Number::New(iso, gamma));
result->Set(context, String::NewFromUtf8(iso, "ok").ToLocalChecked(), Boolean::New(iso, bOk));
result->Set(context, String::NewFromUtf8(iso, "a").ToLocalChecked(), Number::New(iso, a));
result->Set(context, String::NewFromUtf8(iso, "b").ToLocalChecked(), Number::New(iso, b));
result->Set(context, String::NewFromUtf8(iso, "c").ToLocalChecked(), Number::New(iso, c));
result->Set(context, String::NewFromUtf8(iso, "alpha").ToLocalChecked(), Number::New(iso, alpha));
result->Set(context, String::NewFromUtf8(iso, "beta").ToLocalChecked(), Number::New(iso, beta));
result->Set(context, String::NewFromUtf8(iso, "gamma").ToLocalChecked(), Number::New(iso, gamma));
args.GetReturnValue().Set(result);
}
......@@ -309,11 +314,11 @@ void getCIFNumAtoms(const FunctionCallbackInfo<Value>& args) {
if(args.Length() != 1 || !args[0]->IsInt32()) {
auto str = String::NewFromUtf8(iso, "getCIFNumAtoms takes one argument: the CIF handle");
iso->ThrowException(Exception::TypeError(str));
iso->ThrowException(Exception::TypeError(str.ToLocalChecked()));
return;
}
int handle = args[0]->Int32Value();
int handle = Local<Integer>::Cast(args[0])->Value();
int num = accessor.getCIFNumAtoms(handle);
args.GetReturnValue().Set(Integer::New(iso, num));
}
......@@ -324,25 +329,26 @@ void getCIFNumAtoms(const FunctionCallbackInfo<Value>& args) {
*/
void getCIFAtom(const FunctionCallbackInfo<Value>& args) {
auto *iso = args.GetIsolate();
Local<Context> context = iso->GetCurrentContext();
if(args.Length() != 2 || !args[0]->IsInt32() || !args[1]->IsInt32()) {
auto str = String::NewFromUtf8(iso, "getCIFAtom takes two arguments: the CIF handle and the atom index");
iso->ThrowException(Exception::TypeError(str));
iso->ThrowException(Exception::TypeError(str.ToLocalChecked()));
return;
}
int handle = args[0]->Int32Value();
int atomnr = args[1]->Int32Value();
int handle = Local<Integer>::Cast(args[0])->Value();
int atomnr = Local<Integer>::Cast(args[1])->Value();
double x=0, y=0, z=0;
const char* atomname = accessor.getCIFAtom(handle, atomnr, x, y, z);