From 9e6d1fcbd9a3ccf478eaac6deaa1254b006ef017 Mon Sep 17 00:00:00 2001 From: Eduard Bondarenko Date: Sat, 5 May 2018 19:57:55 +0300 Subject: [PATCH 1/2] Add support for node version >= 9 --- README.md | 8 ++- package.json | 13 ++--- src/heapdiff.cc | 7 ++- src/init.cc | 4 +- src/memwatch.cc | 12 +++-- src/memwatch.hh | 2 +- yarn.lock | 135 ++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 162 insertions(+), 19 deletions(-) create mode 100644 yarn.lock diff --git a/README.md b/README.md index 65ac102..d9360de 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ `node-memwatch`: Leak Detection and Heap Diffing for Node.JS ============================================================ -[![Build Status](https://travis-ci.org/deepak1556/node-memwatch.svg?branch=master)](https://travis-ci.org/deepak1556/node-memwatch) - `node-memwatch` is here to help you detect and find memory leaks in Node.JS code. It provides: @@ -19,11 +17,11 @@ Node.JS code. It provides: Installation ------------ -- `npm install memwatch-next` +- `npm install node-memwatch` or -- `git clone git://github.com/marcominetti/node-memwatch.git` +- `git clone https://github.com/eduardbcom/node-memwatch.git` Description @@ -37,7 +35,7 @@ instrumentation. This module attempts to satisfy that need. To get started, import `node-memwatch` like so: ```javascript -var memwatch = require('memwatch-next'); +var memwatch = require('node-memwatch'); ``` ### Leak Detection diff --git a/package.json b/package.json index 1f9d0d7..65fdf8f 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,14 @@ { - "name": "memwatch-next", + "name": "node-memwatch", "description": "Keep an eye on your memory usage, and discover and isolate leaks.", - "version": "0.3.0", + "version": "1.0.0", "author": "Lloyd Hilaiel (http://lloyd.io)", "engines": { - "node": ">= 0.8.0" + "node": ">= 9" }, "repository": { "type": "git", - "url": "https://github.com/marcominetti/node-memwatch.git" + "url": "https://github.com/eduardbcom/node-memwatch.git" }, "main": "include.js", "licenses": [ @@ -17,7 +17,7 @@ } ], "bugs": { - "url": "https://github.com/marcominetti/node-memwatch/issues" + "url": "https://github.com/eduardbcom/node-memwatch/issues" }, "scripts": { "install": "node-gyp rebuild", @@ -30,7 +30,8 @@ "contributors": [ "Jed Parsons (@jedp)", "Jeff Haynie (@jhaynie)", - "Justin Matthews (@jmatthewsr-ms)" + "Justin Matthews (@jmatthewsr-ms)", + "Eduard Bondarenko (@eduardbcom)" ], "dependencies": { "bindings": "^1.2.1", diff --git a/src/heapdiff.cc b/src/heapdiff.cc index aeb2621..cd407c3 100644 --- a/src/heapdiff.cc +++ b/src/heapdiff.cc @@ -90,9 +90,12 @@ NAN_METHOD(heapdiff::HeapDiff::New) info.GetReturnValue().Set(info.This()); } -static string handleToStr(const Handle & str) +static string handleToStr(const Local & str) { - String::Utf8Value utfString(str->ToString()); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + String::Utf8Value utfString(isolate, str->ToString()); + return *utfString; } diff --git a/src/init.cc b/src/init.cc index 36feae9..47e17d2 100644 --- a/src/init.cc +++ b/src/init.cc @@ -11,13 +11,15 @@ extern "C" { void init (v8::Handle target) { + v8::Isolate * isolate = target->GetIsolate(); + Nan::HandleScope scope; heapdiff::HeapDiff::Initialize(target); Nan::SetMethod(target, "upon_gc", memwatch::upon_gc); Nan::SetMethod(target, "gc", memwatch::trigger_gc); - v8::V8::AddGCEpilogueCallback(memwatch::after_gc); + isolate->AddGCEpilogueCallback(memwatch::after_gc); } NODE_MODULE(memwatch, init); diff --git a/src/memwatch.cc b/src/memwatch.cc index 6ebed41..fcf1a81 100644 --- a/src/memwatch.cc +++ b/src/memwatch.cc @@ -125,7 +125,9 @@ static void AsyncMemwatchAfter(uv_work_t* request) { // the type of event to emit argv[1] = Nan::New("leak").ToLocalChecked(); argv[2] = getLeakReport(b->heapUsage); - g_cb->Call(3, argv); + + Nan::AsyncResource async("nan:Callback:Call"); + g_cb->Call(3, argv, &async); } } else { s_stats.consecutive_growth = 0; @@ -200,7 +202,9 @@ static void AsyncMemwatchAfter(uv_work_t* request) { // the type of event to emit argv[1] = Nan::New("stats").ToLocalChecked(); argv[2] = stats; - g_cb->Call(3, argv); + + Nan::AsyncResource async("nan:Callback:Call"); + g_cb->Call(3, argv, &async); } } @@ -209,7 +213,7 @@ static void AsyncMemwatchAfter(uv_work_t* request) { static void noop_work_func(uv_work_t *) { } -void memwatch::after_gc(GCType type, GCCallbackFlags flags) +void memwatch::after_gc(Isolate* isolate, GCType type, GCCallbackFlags flags) { if (heapdiff::HeapDiff::InProgress()) return; @@ -246,7 +250,7 @@ NAN_METHOD(memwatch::trigger_gc) { Nan::HandleScope scope; int deadline_in_ms = 500; if (info.Length() >= 1 && info[0]->IsNumber()) { - deadline_in_ms = (int)(info[0]->Int32Value()); + deadline_in_ms = (int)(info[0]->Int32Value()); } #if (NODE_MODULE_VERSION >= 0x002D) Nan::IdleNotification(deadline_in_ms); diff --git a/src/memwatch.hh b/src/memwatch.hh index 73cde27..0d0b8b8 100644 --- a/src/memwatch.hh +++ b/src/memwatch.hh @@ -12,7 +12,7 @@ namespace memwatch { NAN_METHOD(upon_gc); NAN_METHOD(trigger_gc); - void after_gc(v8::GCType type, v8::GCCallbackFlags flags); + void after_gc(v8::Isolate* isolate, v8::GCType type, v8::GCCallbackFlags flags); }; #endif diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..0e90e56 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,135 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +bindings@^1.2.1: + version "1.3.0" + resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.3.0.tgz#b346f6ecf6a95f5a815c5839fc7cdb22502f1ed7" + +commander@0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/commander/-/commander-0.6.1.tgz#fa68a14f6a945d54dbbe50d8cdb3320e9e3b1a06" + +commander@2.3.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-2.3.0.tgz#fd430e889832ec353b9acd1de217c11cb3eef873" + +debug@2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.2.0.tgz#f87057e995b1a1f6ae6a4960664137bc56f039da" + dependencies: + ms "0.7.1" + +diff@1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/diff/-/diff-1.4.0.tgz#7f28d2eb9ee7b15a97efd89ce63dcfdaa3ccbabf" + +escape-string-regexp@1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz#4dbc2fe674e71949caf3fb2695ce7f2dc1d9a8d1" + +glob@3.2.11: + version "3.2.11" + resolved "https://registry.yarnpkg.com/glob/-/glob-3.2.11.tgz#4a973f635b9190f715d10987d5c00fd2815ebe3d" + dependencies: + inherits "2" + minimatch "0.3" + +growl@1.9.2: + version "1.9.2" + resolved "https://registry.yarnpkg.com/growl/-/growl-1.9.2.tgz#0ea7743715db8d8de2c5ede1775e1b45ac85c02f" + +inherits@2: + version "2.0.3" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" + +jade@0.26.3: + version "0.26.3" + resolved "https://registry.yarnpkg.com/jade/-/jade-0.26.3.tgz#8f10d7977d8d79f2f6ff862a81b0513ccb25686c" + dependencies: + commander "0.6.1" + mkdirp "0.3.0" + +lru-cache@2: + version "2.7.3" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-2.7.3.tgz#6d4524e8b955f95d4f5b58851ce21dd72fb4e952" + +minimatch@0.3: + version "0.3.0" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-0.3.0.tgz#275d8edaac4f1bb3326472089e7949c8394699dd" + dependencies: + lru-cache "2" + sigmund "~1.0.0" + +minimist@0.0.8: + version "0.0.8" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" + +mkdirp@0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.3.0.tgz#1bbf5ab1ba827af23575143490426455f481fe1e" + +mkdirp@0.5.1: + version "0.5.1" + resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" + dependencies: + minimist "0.0.8" + +mocha@^2.4.5: + version "2.5.3" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-2.5.3.tgz#161be5bdeb496771eb9b35745050b622b5aefc58" + dependencies: + commander "2.3.0" + debug "2.2.0" + diff "1.4.0" + escape-string-regexp "1.0.2" + glob "3.2.11" + growl "1.9.2" + jade "0.26.3" + mkdirp "0.5.1" + supports-color "1.2.0" + to-iso-string "0.0.2" + +ms@0.7.1: + version "0.7.1" + resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098" + +nan@^2.3.2: + version "2.10.0" + resolved "https://registry.yarnpkg.com/nan/-/nan-2.10.0.tgz#96d0cd610ebd58d4b4de9cc0c6828cda99c7548f" + +should-equal@0.8.0: + version "0.8.0" + resolved "http://registry.npmjs.org/should-equal/-/should-equal-0.8.0.tgz#a3f05732ff45bac1b7ba412f8408856819641299" + dependencies: + should-type "0.2.0" + +should-format@0.3.2: + version "0.3.2" + resolved "https://registry.yarnpkg.com/should-format/-/should-format-0.3.2.tgz#a59831e01a2ddee149911bc7148be5c80319e1ff" + dependencies: + should-type "0.2.0" + +should-type@0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/should-type/-/should-type-0.2.0.tgz#6707ef95529d989dcc098fe0753ab1f9136bb7f6" + +should@^8.3.1: + version "8.4.0" + resolved "https://registry.yarnpkg.com/should/-/should-8.4.0.tgz#5e60889d3e644bbdd397a30cd34fad28fcf90bc0" + dependencies: + should-equal "0.8.0" + should-format "0.3.2" + should-type "0.2.0" + +sigmund@~1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590" + +supports-color@1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-1.2.0.tgz#ff1ed1e61169d06b3cf2d588e188b18d8847e17e" + +to-iso-string@0.0.2: + version "0.0.2" + resolved "https://registry.yarnpkg.com/to-iso-string/-/to-iso-string-0.0.2.tgz#4dc19e664dfccbe25bd8db508b00c6da158255d1" From 441a44b3f8ebde6b4952d59c6890db310596247e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Wikkeling?= Date: Thu, 25 Oct 2018 18:27:14 +0200 Subject: [PATCH 2/2] changed engine to node >= 8 as it is still in LTS --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 65fdf8f..829563a 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "author": "Lloyd Hilaiel (http://lloyd.io)", "engines": { - "node": ">= 9" + "node": ">= 8" }, "repository": { "type": "git",