Browse Source

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: https://github.com/nodejs/node/pull/11239
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
v6
Ben Noordhuis 8 years ago
parent
commit
bae093a70b
  1. 17
      LICENSE
  2. 10
      Makefile
  3. 1
      test/gc/.gitignore
  4. 80
      test/gc/binding.cc
  5. 9
      test/gc/binding.gyp
  6. 4
      test/gc/test-http-client-connaborted.js
  7. 4
      test/gc/test-http-client-onerror.js
  8. 4
      test/gc/test-http-client-timeout.js
  9. 4
      test/gc/test-http-client.js
  10. 4
      test/gc/test-net-timeout.js
  11. 2
      tools/license-builder.sh
  12. 19
      vcbuild.bat

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. 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: - v8_inspector, located at deps/v8_inspector/third_party/v8_inspector, is licensed as follows:
""" """
// Copyright 2015 The Chromium Authors. All rights reserved. // Copyright 2015 The Chromium Authors. All rights reserved.

10
Makefile

@ -133,10 +133,11 @@ test-parallel: all
test-valgrind: all test-valgrind: all
$(PYTHON) tools/test.py --mode=release --valgrind sequential parallel message $(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 \ $(NODE) deps/npm/node_modules/node-gyp/bin/node-gyp rebuild \
--python="$(PYTHON)" \ --python="$(PYTHON)" \
--directory="$(shell pwd)/test/gc/node_modules/weak" \ --directory="$(shell pwd)/test/gc" \
--nodedir="$(shell pwd)" --nodedir="$(shell pwd)"
# Implicitly depends on $(NODE_EXE), see the build-addons rule for rationale. # 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 | cat
ps awwx | grep Release/node | grep -v grep | awk '{print $$1}' | $(XARGS) kill 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 $(PYTHON) tools/test.py --mode=release gc
test-build: | all build-addons 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 $(PYTHON) tools/test.py --mode=debug,release
test-all-valgrind: test-build test-all-valgrind: test-build
@ -737,6 +738,7 @@ CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard \
test/addons/*/*.h \ test/addons/*/*.h \
test/cctest/*.cc \ test/cctest/*.cc \
test/cctest/*.h \ test/cctest/*.h \
test/gc/binding.cc \
tools/icu/*.cc \ tools/icu/*.cc \
tools/icu/*.h \ tools/icu/*.h \
)) ))

1
test/gc/.gitignore

@ -0,0 +1 @@
build/

80
test/gc/binding.cc

@ -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)

9
test/gc/binding.gyp

@ -0,0 +1,9 @@
{
'targets': [
{
'target_name': 'binding',
'defines': [ 'V8_DEPRECATION_WARNINGS=1' ],
'sources': [ 'binding.cc' ],
},
],
}

4
test/gc/test-http-client-connaborted.js

@ -2,14 +2,14 @@
// just like test/gc/http-client.js, // just like test/gc/http-client.js,
// but aborting every connection that comes in. // but aborting every connection that comes in.
require('../common'); const common = require('../common');
function serverHandler(req, res) { function serverHandler(req, res) {
res.connection.destroy(); res.connection.destroy();
} }
const http = require('http'); const http = require('http');
const weak = require('weak'); const weak = require(`./build/${common.buildType}/binding`);
const todo = 500; const todo = 500;
let done = 0; let done = 0;
let count = 0; let count = 0;

4
test/gc/test-http-client-onerror.js

@ -2,7 +2,7 @@
// just like test/gc/http-client.js, // just like test/gc/http-client.js,
// but with an on('error') handler that does nothing. // but with an on('error') handler that does nothing.
require('../common'); const common = require('../common');
function serverHandler(req, res) { function serverHandler(req, res) {
req.resume(); req.resume();
@ -11,7 +11,7 @@ function serverHandler(req, res) {
} }
const http = require('http'); const http = require('http');
const weak = require('weak'); const weak = require(`./build/${common.buildType}/binding`);
const todo = 500; const todo = 500;
let done = 0; let done = 0;
let count = 0; let count = 0;

4
test/gc/test-http-client-timeout.js

@ -2,7 +2,7 @@
// just like test/gc/http-client.js, // just like test/gc/http-client.js,
// but with a timeout set // but with a timeout set
require('../common'); const common = require('../common');
function serverHandler(req, res) { function serverHandler(req, res) {
setTimeout(function() { setTimeout(function() {
@ -13,7 +13,7 @@ function serverHandler(req, res) {
} }
const http = require('http'); const http = require('http');
const weak = require('weak'); const weak = require(`./build/${common.buildType}/binding`);
const todo = 550; const todo = 550;
let done = 0; let done = 0;
let count = 0; let count = 0;

4
test/gc/test-http-client.js

@ -1,7 +1,7 @@
'use strict'; 'use strict';
// just a simple http server and client. // just a simple http server and client.
require('../common'); const common = require('../common');
function serverHandler(req, res) { function serverHandler(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'}); res.writeHead(200, {'Content-Type': 'text/plain'});
@ -9,7 +9,7 @@ function serverHandler(req, res) {
} }
const http = require('http'); const http = require('http');
const weak = require('weak'); const weak = require(`./build/${common.buildType}/binding`);
const todo = 500; const todo = 500;
let done = 0; let done = 0;
let count = 0; let count = 0;

4
test/gc/test-net-timeout.js

@ -2,7 +2,7 @@
// just like test/gc/http-client-timeout.js, // just like test/gc/http-client-timeout.js,
// but using a net server/client instead // but using a net server/client instead
require('../common'); const common = require('../common');
function serverHandler(sock) { function serverHandler(sock) {
sock.setTimeout(120000); sock.setTimeout(120000);
@ -19,7 +19,7 @@ function serverHandler(sock) {
} }
const net = require('net'); const net = require('net');
const weak = require('weak'); const weak = require(`./build/${common.buildType}/binding`);
const assert = require('assert'); const assert = require('assert');
const todo = 500; const todo = 500;
let done = 0; let done = 0;

2
tools/license-builder.sh

@ -79,8 +79,6 @@ addlicense "cpplint.py" "tools/cpplint.py" \
"$(sed -e '/^$/,$d' -e 's/^#$//' -e 's/^# //' ${rootdir}/tools/cpplint.py | tail -n +3)" "$(sed -e '/^$/,$d' -e 's/^#$//' -e 's/^# //' ${rootdir}/tools/cpplint.py | tail -n +3)"
addlicense "ESLint" "tools/eslint" "$(cat ${rootdir}/tools/eslint/LICENSE)" addlicense "ESLint" "tools/eslint" "$(cat ${rootdir}/tools/eslint/LICENSE)"
addlicense "gtest" "deps/gtest" "$(cat ${rootdir}/deps/gtest/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 # v8_inspector
addlicense "v8_inspector" "deps/v8_inspector/third_party/v8_inspector" \ addlicense "v8_inspector" "deps/v8_inspector/third_party/v8_inspector" \

19
vcbuild.bat

@ -27,7 +27,7 @@ set msi=
set upload= set upload=
set licensertf= set licensertf=
set jslint= set jslint=
set buildnodeweak= set build_testgc_addon=
set noetw= set noetw=
set noetw_msi_arg= set noetw_msi_arg=
set noperfctr= set noperfctr=
@ -62,12 +62,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-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-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-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-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-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-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-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"=="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" set jslint=1&goto arg-ok
if /i "%1"=="jslint-ci" set jslint_ci=1&goto arg-ok if /i "%1"=="jslint-ci" set jslint_ci=1&goto arg-ok
@ -296,15 +296,14 @@ ssh -F %SSHCONFIG% %STAGINGSERVER% "touch nodejs/%DISTTYPEDIR%/v%FULLVERSION%/no
:run :run
@rem Run tests if requested. @rem Run tests if requested.
:build-node-weak @rem Build test/gc add-on if required.
@rem Build node-weak if required if "%build_testgc_addon%"=="" goto build-addons
if "%buildnodeweak%"=="" goto build-addons "%config%\node" deps\npm\node_modules\node-gyp\bin\node-gyp rebuild --directory="%~dp0test\gc" --nodedir="%~dp0."
"%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-testgc-addon-failed
if errorlevel 1 goto build-node-weak-failed
goto build-addons goto build-addons
:build-node-weak-failed :build-testgc-addon-failed
echo Failed to build node-weak. echo Failed to build test/gc add-on."
goto exit goto exit
:build-addons :build-addons

Loading…
Cancel
Save