diff --git a/lib/unix/API.cpp b/lib/unix/API.cpp index 92a8f62..1a96c83 100644 --- a/lib/unix/API.cpp +++ b/lib/unix/API.cpp @@ -14,10 +14,10 @@ namespace API{ for(int i = 0; i < numDests; i++){ Local printer = Object::New(isolate); - printer->Set(UTF8_STRING("name"), UTF8_STRING(dests[i].name)); - printer->Set(UTF8_STRING("default"), Boolean::New(isolate, static_cast(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(dests[i].is_default))); - printers->Set(i, printer); + printers->Set(isolate->GetCurrentContext(), i, printer); } cupsFreeDests(numDests, dests); @@ -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); @@ -50,7 +50,7 @@ namespace API{ Local 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]; @@ -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); } @@ -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); @@ -120,14 +120,14 @@ namespace API{ for (int j = 0; j < group->num_options; j++) { Local 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++; } @@ -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); } @@ -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); diff --git a/lib/unix/API.hpp b/lib/unix/API.hpp index fc5b3f8..e27fac6 100644 --- a/lib/unix/API.hpp +++ b/lib/unix/API.hpp @@ -6,8 +6,9 @@ using namespace v8; #define CALLBACK(name) void name(const FunctionCallbackInfo& 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()))) +#define UTF8_STRING(str) String::NewFromUtf8(isolate, str).FromMaybe(v8::Local()) +#define S_STR(str) isolate, str->ToString(isolate->GetCurrentContext()).FromMaybe(v8::Local()) //Method declarations