Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix - Support for Node V12 #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions lib/unix/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ namespace API{

for(int i = 0; i < numDests; i++){
Local<Object> printer = Object::New(isolate);
printer->Set(UTF8_STRING("name"), UTF8_STRING(dests[i].name));
printer->Set(UTF8_STRING("default"), Boolean::New(isolate, static_cast<bool>(dests[i].is_default)));
printer->Set(isolate->GetCurrentContext(), UTF8_STRING("name"), UTF8_STRING(dests[i].name));
printer->Set(isolate->GetCurrentContext(), UTF8_STRING("default"), Boolean::New(isolate, static_cast<bool>(dests[i].is_default)));

printers->Set(i, printer);
printers->Set(isolate->GetCurrentContext(), i, printer);
}

cupsFreeDests(numDests, dests);
Expand All @@ -33,7 +33,7 @@ namespace API{
return;
}

String::Utf8Value printer(args[0]->ToString());
String::Utf8Value printer(S_STR(args[0]));

cups_dest_t* dest = getPrinter(*printer);

Expand All @@ -50,7 +50,7 @@ namespace API{
Local<Object> CUPSOptions = Object::New(isolate);

for(int i = 0; i < dest->num_options; i++){
CUPSOptions->Set(UTF8_STRING(dest->options[i].name), UTF8_STRING(dest->options[i].value));
CUPSOptions->Set(isolate->GetCurrentContext(), UTF8_STRING(dest->options[i].name), UTF8_STRING(dest->options[i].value));
}

char id[5], priority[5], size[5];
Expand All @@ -62,25 +62,25 @@ namespace API{
sprintf(priority, "%d", printerJobs[i].priority);
sprintf(size, "%d", printerJobs[i].size);

job->Set(UTF8_STRING("completed_time"), UTF8_STRING(httpGetDateString(printerJobs[i].completed_time)));
job->Set(UTF8_STRING("creation_time"), UTF8_STRING(httpGetDateString(printerJobs[i].creation_time)));
job->Set(UTF8_STRING("format"), UTF8_STRING(printerJobs[i].format));
job->Set(UTF8_STRING("id"), UTF8_STRING(id));
job->Set(UTF8_STRING("priority"), UTF8_STRING(priority));
job->Set(UTF8_STRING("processing_time"), UTF8_STRING(httpGetDateString(printerJobs[i].processing_time)));
job->Set(UTF8_STRING("size"), UTF8_STRING(size));
job->Set(UTF8_STRING("status"), UTF8_STRING(getJobStatusString(printerJobs[i].state)));
job->Set(UTF8_STRING("title"), UTF8_STRING(printerJobs[i].title));
job->Set(UTF8_STRING("user"), UTF8_STRING(printerJobs[i].user));

jobs->Set(i, job);
job->Set(isolate->GetCurrentContext(), UTF8_STRING("completed_time"), UTF8_STRING(httpGetDateString(printerJobs[i].completed_time)));
job->Set(isolate->GetCurrentContext(), UTF8_STRING("creation_time"), UTF8_STRING(httpGetDateString(printerJobs[i].creation_time)));
job->Set(isolate->GetCurrentContext(), UTF8_STRING("format"), UTF8_STRING(printerJobs[i].format));
job->Set(isolate->GetCurrentContext(), UTF8_STRING("id"), UTF8_STRING(id));
job->Set(isolate->GetCurrentContext(), UTF8_STRING("priority"), UTF8_STRING(priority));
job->Set(isolate->GetCurrentContext(), UTF8_STRING("processing_time"), UTF8_STRING(httpGetDateString(printerJobs[i].processing_time)));
job->Set(isolate->GetCurrentContext(), UTF8_STRING("size"), UTF8_STRING(size));
job->Set(isolate->GetCurrentContext(), UTF8_STRING("status"), UTF8_STRING(getJobStatusString(printerJobs[i].state)));
job->Set(isolate->GetCurrentContext(), UTF8_STRING("title"), UTF8_STRING(printerJobs[i].title));
job->Set(isolate->GetCurrentContext(), UTF8_STRING("user"), UTF8_STRING(printerJobs[i].user));

jobs->Set(isolate->GetCurrentContext(), i, job);
}

cupsFreeJobs(num_jobs, printerJobs);
free(dest);
// result->Set(UTF8_STRING("infos"), infos);
result->Set(UTF8_STRING("jobs"), jobs);
result->Set(UTF8_STRING("CUPSOptions"), CUPSOptions);
result->Set(isolate->GetCurrentContext(), UTF8_STRING("jobs"), jobs);
result->Set(isolate->GetCurrentContext(), UTF8_STRING("CUPSOptions"), CUPSOptions);

args.GetReturnValue().Set(result);
}
Expand All @@ -93,7 +93,7 @@ namespace API{
return;
}

String::Utf8Value printer(args[0]->ToString());
String::Utf8Value printer(S_STR(args[0]));

cups_dest_t* dest = getPrinter(*printer);

Expand All @@ -120,14 +120,14 @@ namespace API{
for (int j = 0; j < group->num_options; j++)
{
Local<Array> choices = Array::New(isolate, option->num_choices);
resOptions->Set(UTF8_STRING(option->keyword), choices);
resOptions->Set(isolate->GetCurrentContext(), UTF8_STRING(option->keyword), choices);
ppd_choice_t* choice = option->choices;

for(int h = 0; h < option->num_choices; h++){
choices->Set(h, UTF8_STRING(choice->text));
choices->Set(isolate->GetCurrentContext(), h, UTF8_STRING(choice->text));

if(choice->marked)
resDefaults->Set(UTF8_STRING(option->keyword), UTF8_STRING(choice->text));
resDefaults->Set(isolate->GetCurrentContext(), UTF8_STRING(option->keyword), UTF8_STRING(choice->text));

choice++;
}
Expand All @@ -141,8 +141,8 @@ namespace API{
ppdClose(ppd);
free(dest);

result->Set(UTF8_STRING("options"), resOptions);
result->Set(UTF8_STRING("defaultOptions"), resDefaults);
result->Set(isolate->GetCurrentContext(), UTF8_STRING("options"), resOptions);
result->Set(isolate->GetCurrentContext(), UTF8_STRING("defaultOptions"), resDefaults);
args.GetReturnValue().Set(result);
}

Expand All @@ -164,9 +164,9 @@ namespace API{
return;
}

string printer(*(String::Utf8Value(args[0]->ToString())));
string file(*(String::Utf8Value(args[1]->ToString())));
string options(*(String::Utf8Value(args[2]->ToString())));
string printer(*(String::Utf8Value(S_STR(args[0]))));
string file(*(String::Utf8Value(S_STR(args[1]))));
string options(*(String::Utf8Value(S_STR(args[2]))));

cups_dest_t* dest = getPrinter(printer.c_str());
printer = string(dest->name);
Expand Down
5 changes: 3 additions & 2 deletions lib/unix/API.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ using namespace v8;

#define CALLBACK(name) void name(const FunctionCallbackInfo<Value>& args)
#define ISOLATE v8::Isolate* isolate = v8::Isolate::GetCurrent()
#define THROW_EXCEPTION(msg) isolate->ThrowException(v8::Exception::TypeError(String::NewFromUtf8(isolate, msg)))
#define UTF8_STRING(str) String::NewFromUtf8(isolate, str)
#define THROW_EXCEPTION(msg) isolate->ThrowException(v8::Exception::TypeError(String::NewFromUtf8(isolate, msg).FromMaybe(v8::Local<v8::String>())))
#define UTF8_STRING(str) String::NewFromUtf8(isolate, str).FromMaybe(v8::Local<v8::String>())
#define S_STR(str) isolate, str->ToString(isolate->GetCurrentContext()).FromMaybe(v8::Local<v8::String>())


//Method declarations
Expand Down