Permalink
Browse files

test: remove dependency on node-weak

Replace node-weak with a small hand-rolled add-on.  We can now drop
node-weak and nan, reducing the size of the source tree by about 750 kB
and the size of the tarball by about 150-300 kB.

PR-URL: #11239
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
  • Loading branch information...
bnoordhuis authored and italoacasas committed Feb 8, 2017
1 parent 0cded6a commit 969b85cdf5cadf1de24d2ac811afbec63f3c1b0e
View
17 LICENSE
@@ -1071,23 +1071,6 @@ The externally maintained libraries used by Node.js are:
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
-- node-weak, located at test/gc/node_modules/weak, is licensed as follows:
- """
- Copyright (c) 2011, Ben Noordhuis <info@bnoordhuis.nl>
-
- Permission to use, copy, modify, and/or distribute this software for any
- purpose with or without fee is hereby granted, provided that the above
- copyright notice and this permission notice appear in all copies.
-
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- """
-
- v8_inspector, located at deps/v8_inspector/third_party/v8_inspector, is licensed as follows:
"""
// Copyright 2015 The Chromium Authors. All rights reserved.
View
@@ -133,10 +133,11 @@ test-parallel: all
test-valgrind: all
$(PYTHON) tools/test.py --mode=release --valgrind sequential parallel message
-test/gc/node_modules/weak/build/Release/weakref.node: $(NODE_EXE)
+test/gc/build/Release/binding.node: \
+ $(NODE_EXE) test/gc/binding.cc test/gc/binding.gyp
$(NODE) deps/npm/node_modules/node-gyp/bin/node-gyp rebuild \
--python="$(PYTHON)" \
- --directory="$(shell pwd)/test/gc/node_modules/weak" \
+ --directory="$(shell pwd)/test/gc" \
--nodedir="$(shell pwd)"
# Implicitly depends on $(NODE_EXE), see the build-addons rule for rationale.
@@ -197,12 +198,12 @@ clear-stalled:
ps awwx | grep Release/node | grep -v grep | cat
ps awwx | grep Release/node | grep -v grep | awk '{print $$1}' | $(XARGS) kill
-test-gc: all test/gc/node_modules/weak/build/Release/weakref.node
+test-gc: all test/gc/build/Release/binding.node
$(PYTHON) tools/test.py --mode=release gc
test-build: | all build-addons
-test-all: test-build test/gc/node_modules/weak/build/Release/weakref.node
+test-all: test-build test/gc/build/Release/binding.node
$(PYTHON) tools/test.py --mode=debug,release
test-all-valgrind: test-build
@@ -737,6 +738,7 @@ CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard \
test/addons/*/*.h \
test/cctest/*.cc \
test/cctest/*.h \
+ test/gc/binding.cc \
tools/icu/*.cc \
tools/icu/*.h \
))
View
@@ -0,0 +1 @@
+build/
View
@@ -0,0 +1,80 @@
+#include "node.h"
+#include "uv.h"
+
+#include <assert.h>
+#include <stdlib.h>
+
+#include <vector>
+
+#ifdef NDEBUG
+#define CHECK(x) do { if (!(x)) abort(); } while (false)
+#else
+#define CHECK assert
+#endif
+
+#define CHECK_EQ(a, b) CHECK((a) == (b))
+
+namespace {
+
+struct Callback {
+ inline Callback(v8::Isolate* isolate,
+ v8::Local<v8::Object> object,
+ v8::Local<v8::Function> function)
+ : object(isolate, object), function(isolate, function) {}
+
+ v8::Persistent<v8::Object> object;
+ v8::Persistent<v8::Function> function;
+};
+
+static uv_async_t async_handle;
+static std::vector<Callback*> callbacks;
+
+inline void Prime() {
+ uv_ref(reinterpret_cast<uv_handle_t*>(&async_handle));
+ CHECK_EQ(0, uv_async_send(&async_handle));
+}
+
+inline void AsyncCallback(uv_async_t*) {
+ auto isolate = v8::Isolate::GetCurrent();
+ v8::HandleScope handle_scope(isolate);
+ auto context = isolate->GetCurrentContext();
+ auto global = context->Global();
+ while (!callbacks.empty()) {
+ v8::HandleScope handle_scope(isolate);
+ auto callback = callbacks.back();
+ callbacks.pop_back();
+ auto function = v8::Local<v8::Function>::New(isolate, callback->function);
+ delete callback;
+ if (node::MakeCallback(isolate, global, function, 0, nullptr).IsEmpty())
+ return Prime(); // Have exception, flush remainder on next loop tick.
+ }
+ uv_unref(reinterpret_cast<uv_handle_t*>(&async_handle));
+}
+
+inline void OnGC(const v8::FunctionCallbackInfo<v8::Value>& info) {
+ CHECK(info[0]->IsObject());
+ CHECK(info[1]->IsFunction());
+ auto object = info[0].As<v8::Object>();
+ auto function = info[1].As<v8::Function>();
+ auto callback = new Callback(info.GetIsolate(), object, function);
+ auto on_callback = [] (const v8::WeakCallbackInfo<Callback>& data) {
+ auto callback = data.GetParameter();
+ callbacks.push_back(callback);
+ callback->object.Reset();
+ Prime();
+ };
+ callback->object.SetWeak(callback, on_callback,
+ v8::WeakCallbackType::kParameter);
+}
+
+inline void Initialize(v8::Local<v8::Object> exports,
+ v8::Local<v8::Value> module,
+ v8::Local<v8::Context> context) {
+ NODE_SET_METHOD(module->ToObject(context).ToLocalChecked(), "exports", OnGC);
+ CHECK_EQ(0, uv_async_init(uv_default_loop(), &async_handle, AsyncCallback));
+ uv_unref(reinterpret_cast<uv_handle_t*>(&async_handle));
+}
+
+} // anonymous namespace
+
+NODE_MODULE_CONTEXT_AWARE(binding, Initialize)
View
@@ -0,0 +1,9 @@
+{
+ 'targets': [
+ {
+ 'target_name': 'binding',
+ 'defines': [ 'V8_DEPRECATION_WARNINGS=1' ],
+ 'sources': [ 'binding.cc' ],
+ },
+ ],
+}
@@ -2,14 +2,14 @@
// just like test/gc/http-client.js,
// but aborting every connection that comes in.
-require('../common');
+const common = require('../common');
function serverHandler(req, res) {
res.connection.destroy();
}
const http = require('http');
-const weak = require('weak');
+const weak = require(`./build/${common.buildType}/binding`);
const todo = 500;
let done = 0;
let count = 0;
@@ -2,7 +2,7 @@
// just like test/gc/http-client.js,
// but with an on('error') handler that does nothing.
-require('../common');
+const common = require('../common');
function serverHandler(req, res) {
req.resume();
@@ -11,7 +11,7 @@ function serverHandler(req, res) {
}
const http = require('http');
-const weak = require('weak');
+const weak = require(`./build/${common.buildType}/binding`);
const todo = 500;
let done = 0;
let count = 0;
@@ -2,7 +2,7 @@
// just like test/gc/http-client.js,
// but with a timeout set
-require('../common');
+const common = require('../common');
function serverHandler(req, res) {
setTimeout(function() {
@@ -13,7 +13,7 @@ function serverHandler(req, res) {
}
const http = require('http');
-const weak = require('weak');
+const weak = require(`./build/${common.buildType}/binding`);
const todo = 550;
let done = 0;
let count = 0;
@@ -1,15 +1,15 @@
'use strict';
// just a simple http server and client.
-require('../common');
+const common = require('../common');
function serverHandler(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}
const http = require('http');
-const weak = require('weak');
+const weak = require(`./build/${common.buildType}/binding`);
const todo = 500;
let done = 0;
let count = 0;
@@ -2,7 +2,7 @@
// just like test/gc/http-client-timeout.js,
// but using a net server/client instead
-require('../common');
+const common = require('../common');
function serverHandler(sock) {
sock.setTimeout(120000);
@@ -19,7 +19,7 @@ function serverHandler(sock) {
}
const net = require('net');
-const weak = require('weak');
+const weak = require(`./build/${common.buildType}/binding`);
const assert = require('assert');
const todo = 500;
let done = 0;
View
@@ -79,8 +79,6 @@ addlicense "cpplint.py" "tools/cpplint.py" \
"$(sed -e '/^$/,$d' -e 's/^#$//' -e 's/^# //' ${rootdir}/tools/cpplint.py | tail -n +3)"
addlicense "ESLint" "tools/eslint" "$(cat ${rootdir}/tools/eslint/LICENSE)"
addlicense "gtest" "deps/gtest" "$(cat ${rootdir}/deps/gtest/LICENSE)"
-addlicense "node-weak" "test/gc/node_modules/weak" \
- "$(cat ${rootdir}/test/gc/node_modules/weak/LICENSE)"
# v8_inspector
addlicense "v8_inspector" "deps/v8_inspector/third_party/v8_inspector" \
View
@@ -27,7 +27,7 @@ set msi=
set upload=
set licensertf=
set jslint=
-set buildnodeweak=
+set build_testgc_addon=
set noetw=
set noetw_msi_arg=
set noperfctr=
@@ -61,12 +61,12 @@ if /i "%1"=="test-ci" set test_args=%test_args% %test_ci_args% -p tap --lo
if /i "%1"=="test-addons" set test_args=%test_args% addons&set build_addons=1&goto arg-ok
if /i "%1"=="test-simple" set test_args=%test_args% sequential parallel -J&goto arg-ok
if /i "%1"=="test-message" set test_args=%test_args% message&goto arg-ok
-if /i "%1"=="test-gc" set test_args=%test_args% gc&set buildnodeweak=1&goto arg-ok
+if /i "%1"=="test-gc" set test_args=%test_args% gc&set build_testgc_addon=1&goto arg-ok
if /i "%1"=="test-inspector" set test_args=%test_args% inspector&goto arg-ok
if /i "%1"=="test-tick-processor" set test_args=%test_args% tick-processor&goto arg-ok
if /i "%1"=="test-internet" set test_args=%test_args% internet&goto arg-ok
if /i "%1"=="test-pummel" set test_args=%test_args% pummel&goto arg-ok
-if /i "%1"=="test-all" set test_args=%test_args% sequential parallel message gc inspector internet pummel&set buildnodeweak=1&set jslint=1&goto arg-ok
+if /i "%1"=="test-all" set test_args=%test_args% sequential parallel message gc inspector internet pummel&set build_testgc_addon=1&set jslint=1&goto arg-ok
if /i "%1"=="test-known-issues" set test_args=%test_args% known_issues&goto arg-ok
if /i "%1"=="jslint" set jslint=1&goto arg-ok
if /i "%1"=="jslint-ci" set jslint_ci=1&goto arg-ok
@@ -295,15 +295,14 @@ ssh -F %SSHCONFIG% %STAGINGSERVER% "touch nodejs/%DISTTYPEDIR%/v%FULLVERSION%/no
:run
@rem Run tests if requested.
-:build-node-weak
-@rem Build node-weak if required
-if "%buildnodeweak%"=="" goto build-addons
-"%config%\node" deps\npm\node_modules\node-gyp\bin\node-gyp rebuild --directory="%~dp0test\gc\node_modules\weak" --nodedir="%~dp0."
-if errorlevel 1 goto build-node-weak-failed
+@rem Build test/gc add-on if required.
+if "%build_testgc_addon%"=="" goto build-addons
+"%config%\node" deps\npm\node_modules\node-gyp\bin\node-gyp rebuild --directory="%~dp0test\gc" --nodedir="%~dp0."
+if errorlevel 1 goto build-testgc-addon-failed
goto build-addons
-:build-node-weak-failed
-echo Failed to build node-weak.
+:build-testgc-addon-failed
+echo Failed to build test/gc add-on."
goto exit
:build-addons

0 comments on commit 969b85c

Please sign in to comment.