Skip to content

Commit

Permalink
Add new node shims
Browse files Browse the repository at this point in the history
* Added `util.h` and `util-inl.h` for incoming changes to error helpers
  • Loading branch information
kfarnung committed Jul 13, 2017
1 parent 4686a4a commit 4011c96
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// This is a stripped down shim to allow node_api.cc to build outside of the node source tree.
//

#include "util-inl.h"
#include <stdio.h>

// Windows 8+ does not like abort() in Release mode
Expand Down
38 changes: 38 additions & 0 deletions src/util-inl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef SRC_UTIL_INL_H_
#define SRC_UTIL_INL_H_

#include "util.h"
#include "v8.h"

namespace node {

inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
const char* data,
int length) {
return v8::String::NewFromOneByte(isolate,
reinterpret_cast<const uint8_t*>(data),
v8::NewStringType::kNormal,
length).ToLocalChecked();
}

inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
const signed char* data,
int length) {
return v8::String::NewFromOneByte(isolate,
reinterpret_cast<const uint8_t*>(data),
v8::NewStringType::kNormal,
length).ToLocalChecked();
}

inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
const unsigned char* data,
int length) {
return v8::String::NewFromOneByte(isolate,
reinterpret_cast<const uint8_t*>(data),
v8::NewStringType::kNormal,
length).ToLocalChecked();
}

} // namespace node

#endif // SRC_UTIL_INL_H_
7 changes: 7 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef SRC_UTIL_H_
#define SRC_UTIL_H_

#define FIXED_ONE_BYTE_STRING(isolate, string) \
(node::OneByteString((isolate), (string), sizeof(string) - 1))

#endif // SRC_UTIL_H_

0 comments on commit 4011c96

Please sign in to comment.