From a13c8172e8ef998c04720aa4f049747f17948290 Mon Sep 17 00:00:00 2001 From: Felipe Gomes de Melo Date: Fri, 22 Jan 2021 15:33:54 -0300 Subject: [PATCH] [GZNode] Fix compilation errors w/ node 12 Several API calls from V8 were deprecated in version 7.0 (that ships w/ node 12), this commit replaces then Refs: https://github.com/nodejs/node/issues/23122 https://github.com/nodejs/node/pull/23159 https://github.com/bcoin-org/bcrypto/issues/7 --- gzbridge/GZNode.cc | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/gzbridge/GZNode.cc b/gzbridge/GZNode.cc index 64bdb219..8e7444bc 100644 --- a/gzbridge/GZNode.cc +++ b/gzbridge/GZNode.cc @@ -51,8 +51,12 @@ void GZNode::Init(Local exports) { Isolate* isolate = exports->GetIsolate(); // Prepare constructor template + Local class_name = String::NewFromUtf8(isolate, "GZNode", + NewStringType::kInternalized).ToLocalChecked(); + Local tpl = FunctionTemplate::New(isolate, New); - tpl->SetClassName(String::NewFromUtf8(isolate, "GZNode")); + + tpl->SetClassName(class_name); tpl->InstanceTemplate()->SetInternalFieldCount(1); // Prototype NODE_SET_PROTOTYPE_METHOD(tpl, "loadMaterialScripts", LoadMaterialScripts); @@ -80,8 +84,8 @@ void GZNode::Init(Local exports) NODE_SET_PROTOTYPE_METHOD(tpl, "getMaterialScriptsMessage", GetMaterialScriptsMessage); - exports->Set(String::NewFromUtf8(isolate, "GZNode"), - tpl->GetFunction()); + Local context = isolate->GetCurrentContext(); + exports->Set(context, class_name, tpl->GetFunction(context).ToLocalChecked()).Check(); } ///////////////////////////////////////////////// @@ -116,7 +120,7 @@ void GZNode::LoadMaterialScripts(const FunctionCallbackInfo& args) GZNode* obj = ObjectWrap::Unwrap(args.This()); - String::Utf8Value path(args[0]->ToString()); + String::Utf8Value path(isolate, args[0]); obj->gzIface->LoadMaterialScripts(std::string(*path)); return; @@ -125,8 +129,10 @@ void GZNode::LoadMaterialScripts(const FunctionCallbackInfo& args) ///////////////////////////////////////////////// void GZNode::SetConnected(const FunctionCallbackInfo& args) { + Isolate* isolate = args.GetIsolate(); + GZNode *obj = ObjectWrap::Unwrap(args.This()); - bool value = args[0]->BooleanValue(); + bool value = args[0]->BooleanValue(isolate); obj->gzIface->SetConnected(value); return; @@ -160,7 +166,7 @@ void GZNode::GetMaterialScriptsMessage(const FunctionCallbackInfo& args) return; } - String::Utf8Value path(args[0]->ToString()); + String::Utf8Value path(isolate, args[0]); OgreMaterialParser materialParser; materialParser.Load(std::string(*path)); @@ -258,7 +264,7 @@ void GZNode::Request(const FunctionCallbackInfo& args) GZNode* obj = ObjectWrap::Unwrap(args.This()); - String::Utf8Value request(args[0]->ToString()); + String::Utf8Value request(isolate, args[0]); obj->gzIface->PushRequest(std::string(*request)); return;