Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: remove dependency on node-weak #11239

Merged
merged 3 commits into from
Feb 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 \
))
Expand Down
1 change: 1 addition & 0 deletions test/gc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
80 changes: 80 additions & 0 deletions test/gc/binding.cc
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions test/gc/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
'targets': [
{
'target_name': 'binding',
'defines': [ 'V8_DEPRECATION_WARNINGS=1' ],
'sources': [ 'binding.cc' ],
},
],
}
97 changes: 0 additions & 97 deletions test/gc/node_modules/bindings/README.md

This file was deleted.

Loading