Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dtrace_argument.cc 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "dtrace_provider.h"
  2. #include <nan.h>
  3. namespace node {
  4. using namespace v8;
  5. // Integer Argument
  6. #ifdef __x86_64__
  7. # define INTMETHOD ToInteger()
  8. #else
  9. # define INTMETHOD ToInt32()
  10. #endif
  11. void * DTraceIntegerArgument::ArgumentValue(v8::Local<Value> value) {
  12. if (value->IsUndefined())
  13. return 0;
  14. else
  15. return (void *)(long) value->INTMETHOD->Value();
  16. }
  17. void DTraceIntegerArgument::FreeArgument(void *arg) {
  18. }
  19. const char * DTraceIntegerArgument::Type() {
  20. return "int";
  21. }
  22. // String Argument
  23. void * DTraceStringArgument::ArgumentValue(v8::Local<Value> value) {
  24. if (value->IsUndefined())
  25. return (void *) strdup("undefined");
  26. String::Utf8Value str(value->ToString());
  27. return (void *) strdup(*str);
  28. }
  29. void DTraceStringArgument::FreeArgument(void *arg) {
  30. free(arg);
  31. }
  32. const char * DTraceStringArgument::Type() {
  33. return "char *";
  34. }
  35. // JSON Argument
  36. DTraceJsonArgument::DTraceJsonArgument() {
  37. Nan::HandleScope scope;
  38. v8::Local<Context> context = Nan::GetCurrentContext();
  39. v8::Local<Object> global = context->Global();
  40. v8::Local<Object> l_JSON = global->Get(Nan::New<String>("JSON").ToLocalChecked())->ToObject();
  41. v8::Local<Function> l_JSON_stringify
  42. = v8::Local<Function>::Cast(l_JSON->Get(Nan::New<String>("stringify").ToLocalChecked()));
  43. JSON.Reset(l_JSON);
  44. JSON_stringify.Reset(l_JSON_stringify);
  45. }
  46. DTraceJsonArgument::~DTraceJsonArgument() {
  47. JSON.Reset();
  48. JSON_stringify.Reset();
  49. }
  50. void * DTraceJsonArgument::ArgumentValue(v8::Local<Value> value) {
  51. Nan::HandleScope scope;
  52. if (value->IsUndefined())
  53. return (void *) strdup("undefined");
  54. v8::Local<Value> info[1];
  55. info[0] = value;
  56. v8::Local<Value> j = Nan::New<Function>(JSON_stringify)->Call(
  57. Nan::New<Object>(JSON), 1, info);
  58. if (*j == NULL)
  59. return (void *) strdup("{ \"error\": \"stringify failed\" }");
  60. String::Utf8Value json(j->ToString());
  61. return (void *) strdup(*json);
  62. }
  63. void DTraceJsonArgument::FreeArgument(void *arg) {
  64. free(arg);
  65. }
  66. const char * DTraceJsonArgument::Type() {
  67. return "char *";
  68. }
  69. } // namespace node