Skip to content

Commit

Permalink
Major node 12 C++ API update
Browse files Browse the repository at this point in the history
  • Loading branch information
Avaer Kazmer committed Mar 20, 2019
1 parent 2d6b398 commit 9086f74
Show file tree
Hide file tree
Showing 77 changed files with 1,121 additions and 1,111 deletions.
2 changes: 1 addition & 1 deletion deps/exokit-bindings/browser/include/browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace browser {

class Browser : public ObjectWrap {
public:
static Handle<Object> Initialize(Isolate *isolate);
static Local<Object> Initialize(Isolate *isolate);

protected:
Browser(WebGLRenderingContext *gl, int width, int height);
Expand Down
80 changes: 40 additions & 40 deletions deps/exokit-bindings/browser/src/browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Browser::Browser(WebGLRenderingContext *gl, int width, int height) : gl(gl), win

Browser::~Browser() {}

Handle<Object> Browser::Initialize(Isolate *isolate) {
Local<Object> Browser::Initialize(Isolate *isolate) {
uv_async_init(uv_default_loop(), &mainThreadAsync, MainThreadAsync);
// uv_sem_init(&constructSem, 0);
uv_sem_init(&mainThreadSem, 0);
Expand Down Expand Up @@ -64,23 +64,23 @@ Handle<Object> Browser::Initialize(Isolate *isolate) {
Nan::SetMethod(proto, "postMessage", PostMessage);
Nan::SetMethod(proto, "destroy", Destroy);

Local<Function> ctorFn = ctor->GetFunction();
Local<Function> ctorFn = Nan::GetFunction(ctor).ToLocalChecked();
Nan::SetMethod(ctorFn, "updateAll", UpdateAll);

return scope.Escape(ctorFn);
}

NAN_METHOD(Browser::New) {
if (
info[0]->IsObject() && info[0]->ToObject()->Get(JS_STR("constructor"))->ToObject()->Get(JS_STR("name"))->StrictEquals(JS_STR("WebGLRenderingContext")) &&
info[0]->IsObject() && JS_OBJ(JS_OBJ(info[0])->Get(JS_STR("constructor")))->Get(JS_STR("name"))->StrictEquals(JS_STR("WebGLRenderingContext")) &&
info[1]->IsNumber() &&
info[2]->IsNumber() &&
info[3]->IsString()
) {
WebGLRenderingContext *gl = ObjectWrap::Unwrap<WebGLRenderingContext>(Local<Object>::Cast(info[0]));
int width = info[1]->Int32Value();
int height = info[2]->Int32Value();
String::Utf8Value dataPathValue(Local<String>::Cast(info[3]));
int width = TO_INT32(info[1]);
int height = TO_INT32(info[2]);
Nan::Utf8String dataPathValue(Local<String>::Cast(info[3]));
std::string dataPath(*dataPathValue, dataPathValue.length());

if (!embeddedInitialized) {
Expand Down Expand Up @@ -153,7 +153,7 @@ void Browser::loadImmediate(const std::string &url) {

if (!this->onloadstart.IsEmpty()) {
Local<Function> onloadstart = Nan::New(this->onloadstart);
onloadstart->Call(Nan::Null(), 0, nullptr);
onloadstart->Call(Isolate::GetCurrent()->GetCurrentContext(), Nan::Null(), 0, nullptr);
}
});
},
Expand All @@ -166,7 +166,7 @@ void Browser::loadImmediate(const std::string &url) {
JS_STR(url),
};
Local<Function> onloadend = Nan::New(this->onloadend);
onloadend->Call(Nan::Null(), sizeof(argv)/sizeof(argv[0]), argv);
onloadend->Call(Isolate::GetCurrent()->GetCurrentContext(), Nan::Null(), sizeof(argv)/sizeof(argv[0]), argv);
}
});
},
Expand All @@ -181,7 +181,7 @@ void Browser::loadImmediate(const std::string &url) {
JS_STR(errorString),
JS_STR(failedUrl),
};
onloaderror->Call(Nan::Null(), sizeof(argv)/sizeof(argv[0]), argv);
onloaderror->Call(Isolate::GetCurrent()->GetCurrentContext(), Nan::Null(), sizeof(argv)/sizeof(argv[0]), argv);
}
});
},
Expand All @@ -196,7 +196,7 @@ void Browser::loadImmediate(const std::string &url) {
JS_STR(scriptUrl),
JS_INT(startLine),
};
onconsole->Call(Nan::Null(), sizeof(argv)/sizeof(argv[0]), argv);
onconsole->Call(Isolate::GetCurrent()->GetCurrentContext(), Nan::Null(), sizeof(argv)/sizeof(argv[0]), argv);
}
});
},
Expand All @@ -209,7 +209,7 @@ void Browser::loadImmediate(const std::string &url) {
Local<Value> argv[] = {
JS_STR(m),
};
onmessage->Call(Nan::Null(), sizeof(argv)/sizeof(argv[0]), argv);
onmessage->Call(Isolate::GetCurrent()->GetCurrentContext(), Nan::Null(), sizeof(argv)/sizeof(argv[0]), argv);
}
});
}
Expand All @@ -234,8 +234,8 @@ NAN_METHOD(Browser::UpdateAll) {
NAN_METHOD(Browser::Load) {
if (info[0]->IsString()) {
Browser *browser = ObjectWrap::Unwrap<Browser>(info.This());
String::Utf8Value urlUtf8Value(Local<String>::Cast(info[0]));
std::string url(*urlUtf8Value, urlUtf8Value.length());
Nan::Utf8String urlUtf8(Local<String>::Cast(info[0]));
std::string url(*urlUtf8, urlUtf8.length());

browser->load(url);
} else {
Expand All @@ -256,7 +256,7 @@ NAN_GETTER(Browser::WidthGetter) {
NAN_SETTER(Browser::WidthSetter) {
Browser *browser = ObjectWrap::Unwrap<Browser>(info.This());
if (browser->browser_) {
int width = value->Int32Value();
int width = TO_INT32(value);

QueueOnBrowserThread([browser, width]() -> void {
setEmbeddedHeight(browser->browser_, width);
Expand All @@ -276,8 +276,8 @@ NAN_GETTER(Browser::HeightGetter) {
NAN_SETTER(Browser::HeightSetter) {
Browser *browser = ObjectWrap::Unwrap<Browser>(info.This());
if (browser->browser_) {
int height = value->Int32Value();
int height = TO_INT32(value);

QueueOnBrowserThread([browser, height]() -> void {
setEmbeddedHeight(browser->browser_, height);
});
Expand Down Expand Up @@ -390,8 +390,8 @@ NAN_METHOD(Browser::SendMouseMove) {
if (info[0]->IsNumber() && info[1]->IsNumber()) {
Browser *browser = ObjectWrap::Unwrap<Browser>(info.This());
if (browser->browser_) {
int x = info[0]->Int32Value();
int y = info[1]->Int32Value();
int x = TO_INT32(info[0]);
int y = TO_INT32(info[1]);

QueueOnBrowserThread([browser, x, y]() -> void {
embeddedMouseMove(browser->browser_, x, y);
Expand All @@ -406,9 +406,9 @@ NAN_METHOD(Browser::SendMouseDown) {
if (info[0]->IsNumber() && info[1]->IsNumber() && info[2]->IsNumber()) {
Browser *browser = ObjectWrap::Unwrap<Browser>(info.This());
if (browser->browser_) {
int x = info[0]->Int32Value();
int y = info[1]->Int32Value();
int button = info[2]->Int32Value();
int x = TO_INT32(info[0]);
int y = TO_INT32(info[1]);
int button = TO_INT32(info[2]);

QueueOnBrowserThread([browser, x, y, button]() -> void {
embeddedMouseDown(browser->browser_, x, y, button);
Expand All @@ -422,9 +422,9 @@ NAN_METHOD(Browser::SendMouseDown) {
NAN_METHOD(Browser::SendMouseUp) {
if (info[0]->IsNumber() && info[1]->IsNumber() && info[2]->IsNumber()) {
Browser *browser = ObjectWrap::Unwrap<Browser>(info.This());
int x = info[0]->Int32Value();
int y = info[1]->Int32Value();
int button = info[2]->Int32Value();
int x = TO_INT32(info[0]);
int y = TO_INT32(info[1]);
int button = TO_INT32(info[2]);

QueueOnBrowserThread([browser, x, y, button]() -> void {
embeddedMouseUp(browser->browser_, x, y, button);
Expand All @@ -438,10 +438,10 @@ NAN_METHOD(Browser::SendMouseWheel) {
if (info[0]->IsNumber() && info[1]->IsNumber() && info[2]->IsNumber() && info[3]->IsNumber()) {
Browser *browser = ObjectWrap::Unwrap<Browser>(info.This());
if (browser->browser_) {
int x = info[0]->Int32Value();
int y = info[1]->Int32Value();
int deltaX = info[2]->Int32Value();
int deltaY = info[3]->Int32Value();
int x = TO_INT32(info[0]);
int y = TO_INT32(info[1]);
int deltaX = TO_INT32(info[2]);
int deltaY = TO_INT32(info[3]);

QueueOnBrowserThread([browser, x, y, deltaX, deltaY]() -> void {
embeddedMouseWheel(browser->browser_, x, y, deltaX, deltaY);
Expand All @@ -454,13 +454,13 @@ NAN_METHOD(Browser::SendMouseWheel) {

int GetKeyModifiers(Local<Object> modifiersObj) {
int modifiers = 0;
if (modifiersObj->Get(JS_STR("shiftKey"))->BooleanValue()) {
if (TO_BOOL(modifiersObj->Get(JS_STR("shiftKey")))) {
modifiers |= (int)EmbeddedKeyModifiers::SHIFT;
}
if (modifiersObj->Get(JS_STR("ctrlKey"))->BooleanValue()) {
if (TO_BOOL(modifiersObj->Get(JS_STR("ctrlKey")))) {
modifiers |= (int)EmbeddedKeyModifiers::CTRL;
}
if (modifiersObj->Get(JS_STR("altKey"))->BooleanValue()) {
if (TO_BOOL(modifiersObj->Get(JS_STR("altKey")))) {
modifiers |= (int)EmbeddedKeyModifiers::ALT;
}
return modifiers;
Expand Down Expand Up @@ -491,7 +491,7 @@ map<int, int> keyCodesMap{
};

int MutateKey(int key, Local<Object> modifiersObj){
if (modifiersObj->Get(JS_STR("shiftKey"))->BooleanValue()){
if (TO_BOOL(modifiersObj->Get(JS_STR("shiftKey")))){
if (
key >= 97 && // a
key <= 122 // z
Expand All @@ -510,7 +510,7 @@ NAN_METHOD(Browser::SendKeyDown) {
if (info[0]->IsNumber() && info[1]->IsObject()) {
Browser *browser = ObjectWrap::Unwrap<Browser>(info.This());
if (browser->browser_) {
int key = info[0]->Int32Value();
int key = TO_INT32(info[0]);

Local<Object> modifiersObj = Local<Object>::Cast(info[1]);
int modifiers = GetKeyModifiers(modifiersObj);
Expand All @@ -530,7 +530,7 @@ NAN_METHOD(Browser::SendKeyUp) {
if (info[0]->IsNumber() && info[1]->IsObject()) {
Browser *browser = ObjectWrap::Unwrap<Browser>(info.This());
if (browser->browser_) {
int key = info[0]->Int32Value();
int key = TO_INT32(info[0]);

Local<Object> modifiersObj = Local<Object>::Cast(info[1]);
int modifiers = GetKeyModifiers(modifiersObj);
Expand All @@ -550,7 +550,7 @@ NAN_METHOD(Browser::SendKeyPress) {
if (info[0]->IsNumber() && info[1]->IsObject()) {
Browser *browser = ObjectWrap::Unwrap<Browser>(info.This());
if (browser->browser_) {
int key = info[0]->Uint32Value();
int key = TO_UINT32(info[0]);

Local<Object> modifiersObj = Local<Object>::Cast(info[1]);
int modifiers = GetKeyModifiers(modifiersObj);
Expand All @@ -570,13 +570,13 @@ NAN_METHOD(Browser::RunJs) {
Browser *browser = ObjectWrap::Unwrap<Browser>(info.This());

if (browser->browser_) {
String::Utf8Value jsStringValue(Local<String>::Cast(info[0]));
Nan::Utf8String jsStringValue(Local<String>::Cast(info[0]));
string jsString(*jsStringValue, jsStringValue.length());

String::Utf8Value scriptUrlValue(Local<String>::Cast(info[1]));
Nan::Utf8String scriptUrlValue(Local<String>::Cast(info[1]));
string scriptUrl(*scriptUrlValue, scriptUrlValue.length());
int startLine = info[2]->Int32Value();

int startLine = TO_INT32(info[2]);

QueueOnBrowserThread([browser, jsString, scriptUrl, startLine]() -> void {
embeddedRunJs(browser->browser_, jsString, scriptUrl, startLine);
Expand All @@ -598,7 +598,7 @@ NAN_METHOD(Browser::PostMessage) {
Browser *browser = ObjectWrap::Unwrap<Browser>(info.This());

if (browser->browser_) {
String::Utf8Value messageJsonValue(Local<String>::Cast(info[0]));
Nan::Utf8String messageJsonValue(Local<String>::Cast(info[0]));
string messageJson(*messageJsonValue, messageJsonValue.length());

QueueOnBrowserThread([browser, messageJson]() -> void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ enum class Direction {

class CanvasRenderingContext2D : public ObjectWrap {
public:
static Handle<Object> Initialize(Isolate *isolate, Local<Value> imageDataCons, Local<Value> canvasGradientCons, Local<Value> canvasPatternCons);
static Local<Object> Initialize(Isolate *isolate, Local<Value> imageDataCons, Local<Value> canvasGradientCons, Local<Value> canvasPatternCons);
unsigned int GetWidth();
unsigned int GetHeight();
unsigned int GetNumChannels();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using namespace node;

class CanvasGradient : public ObjectWrap {
public:
static Handle<Object> Initialize(Isolate *isolate);
static Local<Object> Initialize(Isolate *isolate);

enum GradientType {
LinearType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using namespace node;

class CanvasPattern : public ObjectWrap {
public:
static Handle<Object> Initialize(Isolate *isolate);
static Local<Object> Initialize(Isolate *isolate);

sk_sp<SkShader> getShader() const;

Expand Down
2 changes: 1 addition & 1 deletion deps/exokit-bindings/canvascontext/include/image-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using namespace node;

class Image : public ObjectWrap {
public:
static Handle<Object> Initialize(Isolate *isolate);
static Local<Object> Initialize(Isolate *isolate);
unsigned int GetWidth();
unsigned int GetHeight();
unsigned int GetNumChannels();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Image;

class ImageBitmap : public ObjectWrap {
public:
static Handle<Object> Initialize(Isolate *isolate);
static Local<Object> Initialize(Isolate *isolate);
unsigned int GetWidth();
unsigned int GetHeight();
unsigned int GetNumChannels();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CanvasRenderingContext2D;

class ImageData : public ObjectWrap {
public:
static Handle<Object> Initialize(Isolate *isolate);
static Local<Object> Initialize(Isolate *isolate);
unsigned int GetWidth();
unsigned int GetHeight();
unsigned int GetNumChannels();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using namespace node;

class Path2D : public ObjectWrap {
public:
static Handle<Object> Initialize(Isolate *isolate);
static Local<Object> Initialize(Isolate *isolate);
void MoveTo(float x, float y);
void LineTo(float x, float y);
void ClosePath();
Expand Down
Loading

0 comments on commit 9086f74

Please sign in to comment.