08-27-周三_17-09-29
This commit is contained in:
3
node_modules/weak/.npmignore
generated
vendored
Normal file
3
node_modules/weak/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/node_modules
|
||||
/build
|
||||
/.lock-wscript
|
36
node_modules/weak/.travis.yml
generated
vendored
Normal file
36
node_modules/weak/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
sudo: false
|
||||
|
||||
env:
|
||||
- CXX=g++-4.8
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-4.8
|
||||
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- "0.8"
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
- "1"
|
||||
- "2"
|
||||
- "3"
|
||||
- "4"
|
||||
- "5"
|
||||
|
||||
install:
|
||||
- PATH="`npm bin`:`npm bin -g`:$PATH"
|
||||
# Node 0.8 comes with a too obsolete npm
|
||||
- if [[ "`node --version`" =~ ^v0\.8\. ]]; then npm install -g npm@1.4.28 ; fi
|
||||
# Install dependencies and build
|
||||
- npm install
|
||||
|
||||
script:
|
||||
# Output useful info for debugging
|
||||
- node --version
|
||||
- npm --version
|
||||
# Run tests
|
||||
- npm test
|
60
node_modules/weak/History.md
generated
vendored
Normal file
60
node_modules/weak/History.md
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
|
||||
1.0.1 / 2016-01-03
|
||||
==================
|
||||
|
||||
* add missing HandleScope in callback (#67, @laverdet)
|
||||
* add Travis support for v4.x, v5.x (#60, @robcolburn)
|
||||
* appveyor: place .bin into the $PATH
|
||||
|
||||
1.0.0 / 2015-08-17
|
||||
==================
|
||||
|
||||
* added `removeCallback()` and `removeCallbacks()`
|
||||
* appveyor: attempt to fix node v0.8
|
||||
* appveyor: test x86 and x64
|
||||
* travis: attempt to fix node v0.8
|
||||
* travis: test "iojs"
|
||||
* travis: run on new infrastructure
|
||||
* package: update to NAN 2.0 (@kkoopa)
|
||||
* package: stricter "bindings" version number
|
||||
* package: specify "MIT" license
|
||||
* README: update for API change
|
||||
|
||||
0.4.1 / 2015-05-09
|
||||
==================
|
||||
|
||||
* Update to nan ~1.8.4 (#47, @imyller)
|
||||
* appveyor: test node v0.12 instead of v0.11
|
||||
|
||||
0.4.0 / 2015-02-18
|
||||
==================
|
||||
|
||||
* travis: test node v0.12
|
||||
* package: update "nan" to v1.6.2 for Node v0.12 compatibility (#40, @GitStarInc)
|
||||
* src: call callback directly to avoid unwanted preemption (#36)
|
||||
|
||||
0.3.4 / 2015-01-27
|
||||
==================
|
||||
|
||||
* Update dependencies to also work with IO.js #39 (#40, @GitStarInc)
|
||||
* Revert "appveyor: attempt to test x86 and x64, Debug and Release configs"
|
||||
* appveyor: attempt to test x86 and x64, Debug and Release configs
|
||||
|
||||
0.3.3 / 2014-06-04
|
||||
==================
|
||||
|
||||
* appveyor: more generic comment
|
||||
* package: update "mocha" to v1.20.1
|
||||
* package: update "nan" to v1.2.0
|
||||
|
||||
0.3.2 / 2014-05-25
|
||||
==================
|
||||
|
||||
* add appveyor.yml file for Windows testing
|
||||
* README: use SVG Travis badge
|
||||
* README: add appveyor build badge
|
||||
* README: correct docs for the callback (#29, @metamatt)
|
||||
* .travis: don't test node v0.9.x
|
||||
* weakref: fix deprecation warning after nan upgrade
|
||||
* weakref: remove "printf()" calls
|
||||
* weakref: update for nan v1 API changes
|
13
node_modules/weak/LICENSE
generated
vendored
Normal file
13
node_modules/weak/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
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.
|
163
node_modules/weak/README.md
generated
vendored
Normal file
163
node_modules/weak/README.md
generated
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
node-weak
|
||||
=========
|
||||
### Make weak references to JavaScript Objects.
|
||||
[](https://travis-ci.org/TooTallNate/node-weak)
|
||||
[](https://ci.appveyor.com/project/TooTallNate/node-weak)
|
||||
|
||||
On certain rarer occasions, you run into the need to be notified when a JavaScript
|
||||
object is going to be garbage collected. This feature is exposed to V8's C++ API,
|
||||
but not to JavaScript.
|
||||
|
||||
That's where `node-weak` comes in! This module exports V8's `Persistent<Object>`
|
||||
functionality to JavaScript. This allows you to create weak references, and
|
||||
optionally attach a callback function to any arbitrary JS object. The callback
|
||||
function will be invoked right before the Object is garbage collected (i.e. after
|
||||
there are no more remaining references to the Object in JS-land).
|
||||
|
||||
This module can, for example, be used for debugging; to determine whether or not
|
||||
an Object is being garbage collected as it should.
|
||||
Take a look at the example below for commented walkthrough scenario.
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
Install with `npm`:
|
||||
|
||||
``` bash
|
||||
$ npm install weak
|
||||
```
|
||||
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
Here's an example of calling a `cleanup()` function on a Object before it gets
|
||||
garbage collected:
|
||||
|
||||
``` js
|
||||
var weak = require('weak')
|
||||
|
||||
// we are going to "monitor" this Object and invoke "cleanup"
|
||||
// before the object is garbage collected
|
||||
var obj = {
|
||||
a: true
|
||||
, foo: 'bar'
|
||||
}
|
||||
|
||||
// Here's where we set up the weak reference
|
||||
var ref = weak(obj, function () {
|
||||
// `this` inside the callback is the EventEmitter.
|
||||
console.log('"obj" has been garbage collected!')
|
||||
})
|
||||
|
||||
// While `obj` is alive, `ref` proxies everything to it, so:
|
||||
ref.a === obj.a
|
||||
ref.foo === obj.foo
|
||||
|
||||
// Clear out any references to the object, so that it will be GC'd at some point...
|
||||
obj = null
|
||||
|
||||
//
|
||||
//// Time passes, and the garbage collector is run
|
||||
//
|
||||
|
||||
// `callback()` above is called, and `ref` now acts like an empty object.
|
||||
typeof ref.foo === 'undefined'
|
||||
```
|
||||
|
||||
|
||||
Weak Callback Function "Best Practices"
|
||||
---------------------------------------
|
||||
|
||||
It's important to be careful when using the "callbacks" feature of `node-weak`,
|
||||
otherwise you can end up in a situation where the watched object will never
|
||||
be garbage collected.
|
||||
|
||||
You _should **not**_ define the callback function in the same scope as the
|
||||
object that is being watched. It's often best to define the callback function
|
||||
at the highest scope possible (top-level being the best). Named functions
|
||||
work really well for this:
|
||||
|
||||
``` js
|
||||
var http = require('http')
|
||||
, weak = require('weak')
|
||||
|
||||
http.createServer(function (req, res) {
|
||||
weak(req, gcReq)
|
||||
weak(res, gcRes)
|
||||
res.end('Hello World\n')
|
||||
}).listen(3000)
|
||||
|
||||
function gcReq () {
|
||||
console.log('GC\'d `req` object')
|
||||
}
|
||||
|
||||
function gcRes () {
|
||||
console.log('GC\'d `res` object')
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
API
|
||||
---
|
||||
|
||||
### Weakref weak(Object obj [, Function callback])
|
||||
|
||||
The main exports is the function that creates the weak reference.
|
||||
The first argument is the Object that should be monitored.
|
||||
The Object can be a regular Object, an Array, a Function, a RegExp, or any of
|
||||
the primitive types or constructor function created with `new`.
|
||||
|
||||
Optionally, you can set a callback function to be invoked
|
||||
before the object is garbage collected.
|
||||
|
||||
|
||||
### Object weak.get(Weakref ref)
|
||||
|
||||
`get()` returns the actual reference to the Object that this weak reference was
|
||||
created with. If this is called with a dead reference, `undefined` is returned.
|
||||
|
||||
|
||||
### Boolean weak.isDead(Weakref ref)
|
||||
|
||||
Checks to see if `ref` is a dead reference. Returns `true` if the original Object
|
||||
has already been GC'd, `false` otherwise.
|
||||
|
||||
|
||||
### Boolean weak.isNearDeath(Weakref ref)
|
||||
|
||||
Checks to see if `ref` is "near death". This will be `true` exactly during the
|
||||
weak reference callback function, and `false` any other time.
|
||||
|
||||
|
||||
### Boolean weak.isWeakRef(Object obj)
|
||||
|
||||
Checks to see if `obj` is "weak reference" instance. Returns `true` if the
|
||||
passed in object is a "weak reference", `false` otherwise.
|
||||
|
||||
|
||||
### EventEmitter weak.addCallback(Weakref ref, Function callback)
|
||||
|
||||
Adds `callback` to the Array of callback functions that will be invoked before the
|
||||
Object gets garbage collected. The callbacks get executed in the order that they
|
||||
are added.
|
||||
|
||||
|
||||
### EventEmitter weak.removeCallback(Weakref ref, Function callback)
|
||||
|
||||
Removes `callback` from the Array of callback functions that will be invoked before
|
||||
the Object gets garbage collected.
|
||||
|
||||
|
||||
### EventEmitter weak.removeCallbacks(Weakref ref)
|
||||
|
||||
Empties the Array of callback functions that will be invoked before the Object gets
|
||||
garbage collected.
|
||||
|
||||
|
||||
### Array weak.callbacks(Weakref ref)
|
||||
|
||||
Returns an Array that `ref` iterates through to invoke the GC callbacks. This
|
||||
utilizes node's `EventEmitter#listeners()` function and therefore returns a copy
|
||||
in node 0.10 and newer.
|
49
node_modules/weak/appveyor.yml
generated
vendored
Normal file
49
node_modules/weak/appveyor.yml
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
# http://www.appveyor.com/docs/appveyor-yml
|
||||
|
||||
# Test against these versions of Node.js.
|
||||
environment:
|
||||
# Visual Studio Version
|
||||
MSVS_VERSION: 2013
|
||||
# Test against these versions of Node.js and io.js
|
||||
matrix:
|
||||
# node.js
|
||||
- nodejs_version: "0.8"
|
||||
- nodejs_version: "0.10"
|
||||
- nodejs_version: "0.12"
|
||||
# io.js
|
||||
- nodejs_version: "2"
|
||||
- nodejs_version: "3"
|
||||
- nodejs_version: "4"
|
||||
- nodejs_version: "5"
|
||||
|
||||
platform:
|
||||
- x86
|
||||
- x64
|
||||
|
||||
# Install scripts. (runs after repo cloning)
|
||||
install:
|
||||
# Get the latest stable version of Node 0.STABLE.latest
|
||||
- ps: if($env:nodejs_version -eq "0.8") {Install-Product node $env:nodejs_version}
|
||||
- ps: if($env:nodejs_version -ne "0.8") {Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version)}
|
||||
# Node 0.8 comes with a too obsolete npm
|
||||
- IF %nodejs_version% == 0.8 (npm install -g npm@1.4.28)
|
||||
# Install latest NPM only for node.js versions until built in node-gyp adds io.js support
|
||||
# Update is required for node.js 0.8 because built in npm(node-gyp) does not know VS2013
|
||||
- IF %nodejs_version% LSS 1 (npm install -g npm@2)
|
||||
- IF %nodejs_version% LSS 1 set PATH=%APPDATA%\npm;%PATH%
|
||||
# Typical npm stuff.
|
||||
- npm install --msvs_version=%MSVS_VERSION%
|
||||
|
||||
# Post-install test scripts.
|
||||
test_script:
|
||||
# Output useful info for debugging.
|
||||
- node --version
|
||||
- npm --version
|
||||
# run tests
|
||||
- npm test
|
||||
|
||||
# Don't actually build.
|
||||
build: off
|
||||
|
||||
# Set build version format here instead of in the admin panel.
|
||||
version: "{build}"
|
9
node_modules/weak/binding.gyp
generated
vendored
Normal file
9
node_modules/weak/binding.gyp
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
'targets': [{
|
||||
'target_name': 'weakref',
|
||||
'sources': [ 'src/weakref.cc' ],
|
||||
'include_dirs': [
|
||||
'<!(node -e "require(\'nan\')")'
|
||||
]
|
||||
}]
|
||||
}
|
324
node_modules/weak/build/Makefile
generated
vendored
Normal file
324
node_modules/weak/build/Makefile
generated
vendored
Normal file
@@ -0,0 +1,324 @@
|
||||
# We borrow heavily from the kernel build setup, though we are simpler since
|
||||
# we don't have Kconfig tweaking settings on us.
|
||||
|
||||
# The implicit make rules have it looking for RCS files, among other things.
|
||||
# We instead explicitly write all the rules we care about.
|
||||
# It's even quicker (saves ~200ms) to pass -r on the command line.
|
||||
MAKEFLAGS=-r
|
||||
|
||||
# The source directory tree.
|
||||
srcdir := ..
|
||||
abs_srcdir := $(abspath $(srcdir))
|
||||
|
||||
# The name of the builddir.
|
||||
builddir_name ?= .
|
||||
|
||||
# The V=1 flag on command line makes us verbosely print command lines.
|
||||
ifdef V
|
||||
quiet=
|
||||
else
|
||||
quiet=quiet_
|
||||
endif
|
||||
|
||||
# Specify BUILDTYPE=Release on the command line for a release build.
|
||||
BUILDTYPE ?= Release
|
||||
|
||||
# Directory all our build output goes into.
|
||||
# Note that this must be two directories beneath src/ for unit tests to pass,
|
||||
# as they reach into the src/ directory for data with relative paths.
|
||||
builddir ?= $(builddir_name)/$(BUILDTYPE)
|
||||
abs_builddir := $(abspath $(builddir))
|
||||
depsdir := $(builddir)/.deps
|
||||
|
||||
# Object output directory.
|
||||
obj := $(builddir)/obj
|
||||
abs_obj := $(abspath $(obj))
|
||||
|
||||
# We build up a list of every single one of the targets so we can slurp in the
|
||||
# generated dependency rule Makefiles in one pass.
|
||||
all_deps :=
|
||||
|
||||
|
||||
|
||||
CC.target ?= $(CC)
|
||||
CFLAGS.target ?= $(CPPFLAGS) $(CFLAGS)
|
||||
CXX.target ?= $(CXX)
|
||||
CXXFLAGS.target ?= $(CPPFLAGS) $(CXXFLAGS)
|
||||
LINK.target ?= $(LINK)
|
||||
LDFLAGS.target ?= $(LDFLAGS)
|
||||
AR.target ?= $(AR)
|
||||
|
||||
# C++ apps need to be linked with g++.
|
||||
LINK ?= $(CXX.target)
|
||||
|
||||
# TODO(evan): move all cross-compilation logic to gyp-time so we don't need
|
||||
# to replicate this environment fallback in make as well.
|
||||
CC.host ?= gcc
|
||||
CFLAGS.host ?= $(CPPFLAGS_host) $(CFLAGS_host)
|
||||
CXX.host ?= g++
|
||||
CXXFLAGS.host ?= $(CPPFLAGS_host) $(CXXFLAGS_host)
|
||||
LINK.host ?= $(CXX.host)
|
||||
LDFLAGS.host ?=
|
||||
AR.host ?= ar
|
||||
|
||||
# Define a dir function that can handle spaces.
|
||||
# http://www.gnu.org/software/make/manual/make.html#Syntax-of-Functions
|
||||
# "leading spaces cannot appear in the text of the first argument as written.
|
||||
# These characters can be put into the argument value by variable substitution."
|
||||
empty :=
|
||||
space := $(empty) $(empty)
|
||||
|
||||
# http://stackoverflow.com/questions/1189781/using-make-dir-or-notdir-on-a-path-with-spaces
|
||||
replace_spaces = $(subst $(space),?,$1)
|
||||
unreplace_spaces = $(subst ?,$(space),$1)
|
||||
dirx = $(call unreplace_spaces,$(dir $(call replace_spaces,$1)))
|
||||
|
||||
# Flags to make gcc output dependency info. Note that you need to be
|
||||
# careful here to use the flags that ccache and distcc can understand.
|
||||
# We write to a dep file on the side first and then rename at the end
|
||||
# so we can't end up with a broken dep file.
|
||||
depfile = $(depsdir)/$(call replace_spaces,$@).d
|
||||
DEPFLAGS = -MMD -MF $(depfile).raw
|
||||
|
||||
# We have to fixup the deps output in a few ways.
|
||||
# (1) the file output should mention the proper .o file.
|
||||
# ccache or distcc lose the path to the target, so we convert a rule of
|
||||
# the form:
|
||||
# foobar.o: DEP1 DEP2
|
||||
# into
|
||||
# path/to/foobar.o: DEP1 DEP2
|
||||
# (2) we want missing files not to cause us to fail to build.
|
||||
# We want to rewrite
|
||||
# foobar.o: DEP1 DEP2 \
|
||||
# DEP3
|
||||
# to
|
||||
# DEP1:
|
||||
# DEP2:
|
||||
# DEP3:
|
||||
# so if the files are missing, they're just considered phony rules.
|
||||
# We have to do some pretty insane escaping to get those backslashes
|
||||
# and dollar signs past make, the shell, and sed at the same time.
|
||||
# Doesn't work with spaces, but that's fine: .d files have spaces in
|
||||
# their names replaced with other characters.
|
||||
define fixup_dep
|
||||
# The depfile may not exist if the input file didn't have any #includes.
|
||||
touch $(depfile).raw
|
||||
# Fixup path as in (1).
|
||||
sed -e "s|^$(notdir $@)|$@|" $(depfile).raw >> $(depfile)
|
||||
# Add extra rules as in (2).
|
||||
# We remove slashes and replace spaces with new lines;
|
||||
# remove blank lines;
|
||||
# delete the first line and append a colon to the remaining lines.
|
||||
sed -e 's|\\||' -e 'y| |\n|' $(depfile).raw |\
|
||||
grep -v '^$$' |\
|
||||
sed -e 1d -e 's|$$|:|' \
|
||||
>> $(depfile)
|
||||
rm $(depfile).raw
|
||||
endef
|
||||
|
||||
# Command definitions:
|
||||
# - cmd_foo is the actual command to run;
|
||||
# - quiet_cmd_foo is the brief-output summary of the command.
|
||||
|
||||
quiet_cmd_cc = CC($(TOOLSET)) $@
|
||||
cmd_cc = $(CC.$(TOOLSET)) $(GYP_CFLAGS) $(DEPFLAGS) $(CFLAGS.$(TOOLSET)) -c -o $@ $<
|
||||
|
||||
quiet_cmd_cxx = CXX($(TOOLSET)) $@
|
||||
cmd_cxx = $(CXX.$(TOOLSET)) $(GYP_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $<
|
||||
|
||||
quiet_cmd_touch = TOUCH $@
|
||||
cmd_touch = touch $@
|
||||
|
||||
quiet_cmd_copy = COPY $@
|
||||
# send stderr to /dev/null to ignore messages when linking directories.
|
||||
cmd_copy = rm -rf "$@" && cp -af "$<" "$@"
|
||||
|
||||
quiet_cmd_alink = AR($(TOOLSET)) $@
|
||||
cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crs $@ $(filter %.o,$^)
|
||||
|
||||
quiet_cmd_alink_thin = AR($(TOOLSET)) $@
|
||||
cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^)
|
||||
|
||||
# Due to circular dependencies between libraries :(, we wrap the
|
||||
# special "figure out circular dependencies" flags around the entire
|
||||
# input list during linking.
|
||||
quiet_cmd_link = LINK($(TOOLSET)) $@
|
||||
cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS)
|
||||
|
||||
# We support two kinds of shared objects (.so):
|
||||
# 1) shared_library, which is just bundling together many dependent libraries
|
||||
# into a link line.
|
||||
# 2) loadable_module, which is generating a module intended for dlopen().
|
||||
#
|
||||
# They differ only slightly:
|
||||
# In the former case, we want to package all dependent code into the .so.
|
||||
# In the latter case, we want to package just the API exposed by the
|
||||
# outermost module.
|
||||
# This means shared_library uses --whole-archive, while loadable_module doesn't.
|
||||
# (Note that --whole-archive is incompatible with the --start-group used in
|
||||
# normal linking.)
|
||||
|
||||
# Other shared-object link notes:
|
||||
# - Set SONAME to the library filename so our binaries don't reference
|
||||
# the local, absolute paths used on the link command-line.
|
||||
quiet_cmd_solink = SOLINK($(TOOLSET)) $@
|
||||
cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--whole-archive $(LD_INPUTS) -Wl,--no-whole-archive $(LIBS)
|
||||
|
||||
quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
|
||||
cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--start-group $(filter-out FORCE_DO_CMD, $^) -Wl,--end-group $(LIBS)
|
||||
|
||||
|
||||
# Define an escape_quotes function to escape single quotes.
|
||||
# This allows us to handle quotes properly as long as we always use
|
||||
# use single quotes and escape_quotes.
|
||||
escape_quotes = $(subst ','\'',$(1))
|
||||
# This comment is here just to include a ' to unconfuse syntax highlighting.
|
||||
# Define an escape_vars function to escape '$' variable syntax.
|
||||
# This allows us to read/write command lines with shell variables (e.g.
|
||||
# $LD_LIBRARY_PATH), without triggering make substitution.
|
||||
escape_vars = $(subst $$,$$$$,$(1))
|
||||
# Helper that expands to a shell command to echo a string exactly as it is in
|
||||
# make. This uses printf instead of echo because printf's behaviour with respect
|
||||
# to escape sequences is more portable than echo's across different shells
|
||||
# (e.g., dash, bash).
|
||||
exact_echo = printf '%s\n' '$(call escape_quotes,$(1))'
|
||||
|
||||
# Helper to compare the command we're about to run against the command
|
||||
# we logged the last time we ran the command. Produces an empty
|
||||
# string (false) when the commands match.
|
||||
# Tricky point: Make has no string-equality test function.
|
||||
# The kernel uses the following, but it seems like it would have false
|
||||
# positives, where one string reordered its arguments.
|
||||
# arg_check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \
|
||||
# $(filter-out $(cmd_$@), $(cmd_$(1))))
|
||||
# We instead substitute each for the empty string into the other, and
|
||||
# say they're equal if both substitutions produce the empty string.
|
||||
# .d files contain ? instead of spaces, take that into account.
|
||||
command_changed = $(or $(subst $(cmd_$(1)),,$(cmd_$(call replace_spaces,$@))),\
|
||||
$(subst $(cmd_$(call replace_spaces,$@)),,$(cmd_$(1))))
|
||||
|
||||
# Helper that is non-empty when a prerequisite changes.
|
||||
# Normally make does this implicitly, but we force rules to always run
|
||||
# so we can check their command lines.
|
||||
# $? -- new prerequisites
|
||||
# $| -- order-only dependencies
|
||||
prereq_changed = $(filter-out FORCE_DO_CMD,$(filter-out $|,$?))
|
||||
|
||||
# Helper that executes all postbuilds until one fails.
|
||||
define do_postbuilds
|
||||
@E=0;\
|
||||
for p in $(POSTBUILDS); do\
|
||||
eval $$p;\
|
||||
E=$$?;\
|
||||
if [ $$E -ne 0 ]; then\
|
||||
break;\
|
||||
fi;\
|
||||
done;\
|
||||
if [ $$E -ne 0 ]; then\
|
||||
rm -rf "$@";\
|
||||
exit $$E;\
|
||||
fi
|
||||
endef
|
||||
|
||||
# do_cmd: run a command via the above cmd_foo names, if necessary.
|
||||
# Should always run for a given target to handle command-line changes.
|
||||
# Second argument, if non-zero, makes it do asm/C/C++ dependency munging.
|
||||
# Third argument, if non-zero, makes it do POSTBUILDS processing.
|
||||
# Note: We intentionally do NOT call dirx for depfile, since it contains ? for
|
||||
# spaces already and dirx strips the ? characters.
|
||||
define do_cmd
|
||||
$(if $(or $(command_changed),$(prereq_changed)),
|
||||
@$(call exact_echo, $($(quiet)cmd_$(1)))
|
||||
@mkdir -p "$(call dirx,$@)" "$(dir $(depfile))"
|
||||
$(if $(findstring flock,$(word 1,$(cmd_$1))),
|
||||
@$(cmd_$(1))
|
||||
@echo " $(quiet_cmd_$(1)): Finished",
|
||||
@$(cmd_$(1))
|
||||
)
|
||||
@$(call exact_echo,$(call escape_vars,cmd_$(call replace_spaces,$@) := $(cmd_$(1)))) > $(depfile)
|
||||
@$(if $(2),$(fixup_dep))
|
||||
$(if $(and $(3), $(POSTBUILDS)),
|
||||
$(call do_postbuilds)
|
||||
)
|
||||
)
|
||||
endef
|
||||
|
||||
# Declare the "all" target first so it is the default,
|
||||
# even though we don't have the deps yet.
|
||||
.PHONY: all
|
||||
all:
|
||||
|
||||
# make looks for ways to re-generate included makefiles, but in our case, we
|
||||
# don't have a direct way. Explicitly telling make that it has nothing to do
|
||||
# for them makes it go faster.
|
||||
%.d: ;
|
||||
|
||||
# Use FORCE_DO_CMD to force a target to run. Should be coupled with
|
||||
# do_cmd.
|
||||
.PHONY: FORCE_DO_CMD
|
||||
FORCE_DO_CMD:
|
||||
|
||||
TOOLSET := target
|
||||
# Suffix rules, putting all outputs into $(obj).
|
||||
$(obj).$(TOOLSET)/%.o: $(srcdir)/%.c FORCE_DO_CMD
|
||||
@$(call do_cmd,cc,1)
|
||||
$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cc FORCE_DO_CMD
|
||||
@$(call do_cmd,cxx,1)
|
||||
$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cpp FORCE_DO_CMD
|
||||
@$(call do_cmd,cxx,1)
|
||||
$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cxx FORCE_DO_CMD
|
||||
@$(call do_cmd,cxx,1)
|
||||
$(obj).$(TOOLSET)/%.o: $(srcdir)/%.S FORCE_DO_CMD
|
||||
@$(call do_cmd,cc,1)
|
||||
$(obj).$(TOOLSET)/%.o: $(srcdir)/%.s FORCE_DO_CMD
|
||||
@$(call do_cmd,cc,1)
|
||||
|
||||
# Try building from generated source, too.
|
||||
$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.c FORCE_DO_CMD
|
||||
@$(call do_cmd,cc,1)
|
||||
$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cc FORCE_DO_CMD
|
||||
@$(call do_cmd,cxx,1)
|
||||
$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cpp FORCE_DO_CMD
|
||||
@$(call do_cmd,cxx,1)
|
||||
$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cxx FORCE_DO_CMD
|
||||
@$(call do_cmd,cxx,1)
|
||||
$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.S FORCE_DO_CMD
|
||||
@$(call do_cmd,cc,1)
|
||||
$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.s FORCE_DO_CMD
|
||||
@$(call do_cmd,cc,1)
|
||||
|
||||
$(obj).$(TOOLSET)/%.o: $(obj)/%.c FORCE_DO_CMD
|
||||
@$(call do_cmd,cc,1)
|
||||
$(obj).$(TOOLSET)/%.o: $(obj)/%.cc FORCE_DO_CMD
|
||||
@$(call do_cmd,cxx,1)
|
||||
$(obj).$(TOOLSET)/%.o: $(obj)/%.cpp FORCE_DO_CMD
|
||||
@$(call do_cmd,cxx,1)
|
||||
$(obj).$(TOOLSET)/%.o: $(obj)/%.cxx FORCE_DO_CMD
|
||||
@$(call do_cmd,cxx,1)
|
||||
$(obj).$(TOOLSET)/%.o: $(obj)/%.S FORCE_DO_CMD
|
||||
@$(call do_cmd,cc,1)
|
||||
$(obj).$(TOOLSET)/%.o: $(obj)/%.s FORCE_DO_CMD
|
||||
@$(call do_cmd,cc,1)
|
||||
|
||||
|
||||
ifeq ($(strip $(foreach prefix,$(NO_LOAD),\
|
||||
$(findstring $(join ^,$(prefix)),\
|
||||
$(join ^,weakref.target.mk)))),)
|
||||
include weakref.target.mk
|
||||
endif
|
||||
|
||||
quiet_cmd_regen_makefile = ACTION Regenerating $@
|
||||
cmd_regen_makefile = cd $(srcdir); /root/.gitbook/versions/3.2.3/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py -fmake --ignore-environment "--toplevel-dir=." -I/root/gitbook/node_modules/weak/build/config.gypi -I/root/.gitbook/versions/3.2.3/node_modules/npm/node_modules/node-gyp/addon.gypi -I/root/.node-gyp/10.24.1/include/node/common.gypi "--depth=." "-Goutput_dir=." "--generator-output=build" "-Dlibrary=shared_library" "-Dvisibility=default" "-Dnode_root_dir=/root/.node-gyp/10.24.1" "-Dnode_gyp_dir=/root/.gitbook/versions/3.2.3/node_modules/npm/node_modules/node-gyp" "-Dnode_lib_file=node.lib" "-Dmodule_root_dir=/root/gitbook/node_modules/weak" binding.gyp
|
||||
Makefile: $(srcdir)/../../../.node-gyp/10.24.1/include/node/common.gypi $(srcdir)/build/config.gypi $(srcdir)/binding.gyp $(srcdir)/../../../.gitbook/versions/3.2.3/node_modules/npm/node_modules/node-gyp/addon.gypi
|
||||
$(call do_cmd,regen_makefile)
|
||||
|
||||
# "all" is a concatenation of the "all" targets from all the included
|
||||
# sub-makefiles. This is just here to clarify.
|
||||
all:
|
||||
|
||||
# Add in dependency-tracking rules. $(all_deps) is the list of every single
|
||||
# target in our tree. Only consider the ones with .d (dependency) info:
|
||||
d_files := $(wildcard $(foreach f,$(all_deps),$(depsdir)/$(f).d))
|
||||
ifneq ($(d_files),)
|
||||
include $(d_files)
|
||||
endif
|
6
node_modules/weak/build/binding.Makefile
generated
vendored
Normal file
6
node_modules/weak/build/binding.Makefile
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
# This file is generated by gyp; do not edit.
|
||||
|
||||
export builddir_name ?= ./build/.
|
||||
.PHONY: all
|
||||
all:
|
||||
$(MAKE) weakref
|
168
node_modules/weak/build/config.gypi
generated
vendored
Normal file
168
node_modules/weak/build/config.gypi
generated
vendored
Normal file
@@ -0,0 +1,168 @@
|
||||
# Do not edit. File was generated by node-gyp's "configure" step
|
||||
{
|
||||
"target_defaults": {
|
||||
"cflags": [],
|
||||
"default_configuration": "Release",
|
||||
"defines": [],
|
||||
"include_dirs": [],
|
||||
"libraries": []
|
||||
},
|
||||
"variables": {
|
||||
"asan": 0,
|
||||
"build_v8_with_gn": "false",
|
||||
"coverage": "false",
|
||||
"debug_nghttp2": "false",
|
||||
"enable_lto": "false",
|
||||
"enable_pgo_generate": "false",
|
||||
"enable_pgo_use": "false",
|
||||
"force_dynamic_crt": 0,
|
||||
"gas_version": "2.27",
|
||||
"host_arch": "x64",
|
||||
"icu_data_in": "../../deps/icu-small/source/data/in/icudt64l.dat",
|
||||
"icu_endianness": "l",
|
||||
"icu_gyp_path": "tools/icu/icu-generic.gyp",
|
||||
"icu_locales": "en,root",
|
||||
"icu_path": "deps/icu-small",
|
||||
"icu_small": "true",
|
||||
"icu_ver_major": "64",
|
||||
"llvm_version": 0,
|
||||
"napi_build_version": "7",
|
||||
"node_byteorder": "little",
|
||||
"node_debug_lib": "false",
|
||||
"node_enable_d8": "false",
|
||||
"node_enable_v8_vtunejit": "false",
|
||||
"node_install_npm": "true",
|
||||
"node_module_version": 64,
|
||||
"node_no_browser_globals": "false",
|
||||
"node_prefix": "/",
|
||||
"node_release_urlbase": "https://nodejs.org/download/release/",
|
||||
"node_shared": "false",
|
||||
"node_shared_cares": "false",
|
||||
"node_shared_http_parser": "false",
|
||||
"node_shared_libuv": "false",
|
||||
"node_shared_nghttp2": "false",
|
||||
"node_shared_openssl": "false",
|
||||
"node_shared_zlib": "false",
|
||||
"node_tag": "",
|
||||
"node_target_type": "executable",
|
||||
"node_use_bundled_v8": "true",
|
||||
"node_use_dtrace": "false",
|
||||
"node_use_etw": "false",
|
||||
"node_use_large_pages": "false",
|
||||
"node_use_openssl": "true",
|
||||
"node_use_pch": "false",
|
||||
"node_use_perfctr": "false",
|
||||
"node_use_v8_platform": "true",
|
||||
"node_with_ltcg": "false",
|
||||
"node_without_node_options": "false",
|
||||
"openssl_fips": "",
|
||||
"openssl_no_asm": 0,
|
||||
"shlib_suffix": "so.64",
|
||||
"target_arch": "x64",
|
||||
"v8_enable_gdbjit": 0,
|
||||
"v8_enable_i18n_support": 1,
|
||||
"v8_enable_inspector": 1,
|
||||
"v8_no_strict_aliasing": 1,
|
||||
"v8_optimized_debug": 0,
|
||||
"v8_promise_internal_field_count": 1,
|
||||
"v8_random_seed": 0,
|
||||
"v8_trace_maps": 0,
|
||||
"v8_typed_array_max_size_in_heap": 0,
|
||||
"v8_use_snapshot": "true",
|
||||
"want_separate_host_toolset": 0,
|
||||
"nodedir": "/root/.node-gyp/10.24.1",
|
||||
"copy_dev_lib": "true",
|
||||
"standalone_static_library": 1,
|
||||
"dry_run": "",
|
||||
"legacy_bundling": "",
|
||||
"save_dev": "",
|
||||
"browser": "",
|
||||
"only": "",
|
||||
"viewer": "man",
|
||||
"also": "",
|
||||
"rollback": "true",
|
||||
"usage": "",
|
||||
"globalignorefile": "/root/.nvm/versions/node/v10.24.1/etc/npmignore",
|
||||
"init_author_url": "",
|
||||
"maxsockets": "50",
|
||||
"shell": "/bin/bash",
|
||||
"silent": "true",
|
||||
"parseable": "",
|
||||
"shrinkwrap": "true",
|
||||
"init_license": "ISC",
|
||||
"if_present": "",
|
||||
"cache_max": "Infinity",
|
||||
"init_author_email": "",
|
||||
"sign_git_tag": "",
|
||||
"cert": "",
|
||||
"git_tag_version": "true",
|
||||
"local_address": "",
|
||||
"long": "",
|
||||
"fetch_retries": "2",
|
||||
"npat": "",
|
||||
"registry": "https://registry.npmjs.org/",
|
||||
"key": "",
|
||||
"message": "%s",
|
||||
"versions": "",
|
||||
"globalconfig": "/root/.nvm/versions/node/v10.24.1/etc/npmrc",
|
||||
"always_auth": "",
|
||||
"cache_lock_retries": "10",
|
||||
"global_style": "",
|
||||
"heading": "npm",
|
||||
"fetch_retry_mintimeout": "10000",
|
||||
"proprietary_attribs": "true",
|
||||
"access": "",
|
||||
"json": "",
|
||||
"description": "true",
|
||||
"engine_strict": "",
|
||||
"https_proxy": "",
|
||||
"init_module": "/root/.npm-init.js",
|
||||
"userconfig": "/root/.npmrc",
|
||||
"node_version": "10.24.1",
|
||||
"user": "",
|
||||
"editor": "vi",
|
||||
"save": "",
|
||||
"tag": "latest",
|
||||
"global": "",
|
||||
"progress": "true",
|
||||
"optional": "true",
|
||||
"bin_links": "true",
|
||||
"force": "",
|
||||
"searchopts": "",
|
||||
"depth": "Infinity",
|
||||
"rebuild_bundle": "true",
|
||||
"searchsort": "name",
|
||||
"unicode": "true",
|
||||
"fetch_retry_maxtimeout": "60000",
|
||||
"ca": "",
|
||||
"save_prefix": "^",
|
||||
"strict_ssl": "true",
|
||||
"tag_version_prefix": "v",
|
||||
"dev": "",
|
||||
"fetch_retry_factor": "10",
|
||||
"group": "",
|
||||
"save_exact": "",
|
||||
"cache_lock_stale": "60000",
|
||||
"version": "",
|
||||
"cache_min": "10",
|
||||
"cache": "/root/.npm",
|
||||
"searchexclude": "",
|
||||
"color": "true",
|
||||
"save_optional": "",
|
||||
"user_agent": "npm/3.9.2 node/v10.24.1 linux x64",
|
||||
"ignore_scripts": "",
|
||||
"cache_lock_wait": "10000",
|
||||
"production": "",
|
||||
"save_bundle": "",
|
||||
"init_version": "1.0.0",
|
||||
"umask": "0022",
|
||||
"git": "git",
|
||||
"init_author_name": "",
|
||||
"scope": "",
|
||||
"onload_script": "",
|
||||
"tmp": "/tmp",
|
||||
"unsafe_perm": "",
|
||||
"link": "",
|
||||
"prefix": "/root/.nvm/versions/node/v10.24.1"
|
||||
}
|
||||
}
|
139
node_modules/weak/build/weakref.target.mk
generated
vendored
Normal file
139
node_modules/weak/build/weakref.target.mk
generated
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
# This file is generated by gyp; do not edit.
|
||||
|
||||
TOOLSET := target
|
||||
TARGET := weakref
|
||||
DEFS_Debug := \
|
||||
'-DNODE_GYP_MODULE_NAME=weakref' \
|
||||
'-D_LARGEFILE_SOURCE' \
|
||||
'-D_FILE_OFFSET_BITS=64' \
|
||||
'-DOPENSSL_NO_PINSHARED' \
|
||||
'-DBUILDING_NODE_EXTENSION' \
|
||||
'-DDEBUG' \
|
||||
'-D_DEBUG' \
|
||||
'-DV8_ENABLE_CHECKS'
|
||||
|
||||
# Flags passed to all source files.
|
||||
CFLAGS_Debug := \
|
||||
-fPIC \
|
||||
-pthread \
|
||||
-Wall \
|
||||
-Wextra \
|
||||
-Wno-unused-parameter \
|
||||
-m64 \
|
||||
-g \
|
||||
-O0
|
||||
|
||||
# Flags passed to only C files.
|
||||
CFLAGS_C_Debug :=
|
||||
|
||||
# Flags passed to only C++ files.
|
||||
CFLAGS_CC_Debug := \
|
||||
-fno-rtti \
|
||||
-fno-exceptions \
|
||||
-std=gnu++1y
|
||||
|
||||
INCS_Debug := \
|
||||
-I/root/.node-gyp/10.24.1/include/node \
|
||||
-I/root/.node-gyp/10.24.1/src \
|
||||
-I/root/.node-gyp/10.24.1/deps/uv/include \
|
||||
-I/root/.node-gyp/10.24.1/deps/v8/include \
|
||||
-I$(srcdir)/../nan
|
||||
|
||||
DEFS_Release := \
|
||||
'-DNODE_GYP_MODULE_NAME=weakref' \
|
||||
'-D_LARGEFILE_SOURCE' \
|
||||
'-D_FILE_OFFSET_BITS=64' \
|
||||
'-DOPENSSL_NO_PINSHARED' \
|
||||
'-DBUILDING_NODE_EXTENSION'
|
||||
|
||||
# Flags passed to all source files.
|
||||
CFLAGS_Release := \
|
||||
-fPIC \
|
||||
-pthread \
|
||||
-Wall \
|
||||
-Wextra \
|
||||
-Wno-unused-parameter \
|
||||
-m64 \
|
||||
-O3 \
|
||||
-fno-omit-frame-pointer
|
||||
|
||||
# Flags passed to only C files.
|
||||
CFLAGS_C_Release :=
|
||||
|
||||
# Flags passed to only C++ files.
|
||||
CFLAGS_CC_Release := \
|
||||
-fno-rtti \
|
||||
-fno-exceptions \
|
||||
-std=gnu++1y
|
||||
|
||||
INCS_Release := \
|
||||
-I/root/.node-gyp/10.24.1/include/node \
|
||||
-I/root/.node-gyp/10.24.1/src \
|
||||
-I/root/.node-gyp/10.24.1/deps/uv/include \
|
||||
-I/root/.node-gyp/10.24.1/deps/v8/include \
|
||||
-I$(srcdir)/../nan
|
||||
|
||||
OBJS := \
|
||||
$(obj).target/$(TARGET)/src/weakref.o
|
||||
|
||||
# Add to the list of files we specially track dependencies for.
|
||||
all_deps += $(OBJS)
|
||||
|
||||
# CFLAGS et al overrides must be target-local.
|
||||
# See "Target-specific Variable Values" in the GNU Make manual.
|
||||
$(OBJS): TOOLSET := $(TOOLSET)
|
||||
$(OBJS): GYP_CFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_C_$(BUILDTYPE))
|
||||
$(OBJS): GYP_CXXFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_CC_$(BUILDTYPE))
|
||||
|
||||
# Suffix rules, putting all outputs into $(obj).
|
||||
|
||||
$(obj).$(TOOLSET)/$(TARGET)/%.o: $(srcdir)/%.cc FORCE_DO_CMD
|
||||
@$(call do_cmd,cxx,1)
|
||||
|
||||
# Try building from generated source, too.
|
||||
|
||||
$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj).$(TOOLSET)/%.cc FORCE_DO_CMD
|
||||
@$(call do_cmd,cxx,1)
|
||||
|
||||
$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.cc FORCE_DO_CMD
|
||||
@$(call do_cmd,cxx,1)
|
||||
|
||||
# End of this set of suffix rules
|
||||
### Rules for final target.
|
||||
LDFLAGS_Debug := \
|
||||
-pthread \
|
||||
-rdynamic \
|
||||
-m64
|
||||
|
||||
LDFLAGS_Release := \
|
||||
-pthread \
|
||||
-rdynamic \
|
||||
-m64
|
||||
|
||||
LIBS :=
|
||||
|
||||
$(obj).target/weakref.node: GYP_LDFLAGS := $(LDFLAGS_$(BUILDTYPE))
|
||||
$(obj).target/weakref.node: LIBS := $(LIBS)
|
||||
$(obj).target/weakref.node: TOOLSET := $(TOOLSET)
|
||||
$(obj).target/weakref.node: $(OBJS) FORCE_DO_CMD
|
||||
$(call do_cmd,solink_module)
|
||||
|
||||
all_deps += $(obj).target/weakref.node
|
||||
# Add target alias
|
||||
.PHONY: weakref
|
||||
weakref: $(builddir)/weakref.node
|
||||
|
||||
# Copy this to the executable output path.
|
||||
$(builddir)/weakref.node: TOOLSET := $(TOOLSET)
|
||||
$(builddir)/weakref.node: $(obj).target/weakref.node FORCE_DO_CMD
|
||||
$(call do_cmd,copy)
|
||||
|
||||
all_deps += $(builddir)/weakref.node
|
||||
# Short alias for building this executable.
|
||||
.PHONY: weakref.node
|
||||
weakref.node: $(obj).target/weakref.node $(builddir)/weakref.node
|
||||
|
||||
# Add executable to "all" target.
|
||||
.PHONY: all
|
||||
all: $(builddir)/weakref.node
|
||||
|
110
node_modules/weak/lib/weak.js
generated
vendored
Normal file
110
node_modules/weak/lib/weak.js
generated
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Emitter = require('events').EventEmitter;
|
||||
var bindings = require('bindings')('weakref.node');
|
||||
|
||||
/**
|
||||
* Set global weak callback function.
|
||||
*/
|
||||
|
||||
bindings._setCallback(callback);
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
*/
|
||||
|
||||
exports = module.exports = create;
|
||||
exports.addCallback = exports.addListener = addCallback;
|
||||
exports.removeCallback = exports.removeListener = removeCallback;
|
||||
exports.removeCallbacks = exports.removeListeners = removeCallbacks;
|
||||
exports.callbacks = exports.listeners = callbacks;
|
||||
|
||||
// backwards-compat with node-weakref
|
||||
exports.weaken = exports.create = exports;
|
||||
|
||||
// re-export all the binding functions onto the exports
|
||||
Object.keys(bindings).forEach(function (name) {
|
||||
exports[name] = bindings[name];
|
||||
});
|
||||
|
||||
/**
|
||||
* Internal emitter event name.
|
||||
* This is completely arbitrary...
|
||||
* Could be any value....
|
||||
*/
|
||||
|
||||
var CB = '_CB';
|
||||
|
||||
/**
|
||||
* Creates and returns a new Weakref instance. Optionally attaches
|
||||
* a weak callback to invoke when the Object gets garbage collected.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function create (obj, fn) {
|
||||
var weakref = bindings._create(obj, new Emitter());
|
||||
if ('function' == typeof fn) {
|
||||
exports.addCallback(weakref, fn);
|
||||
}
|
||||
return weakref;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a weak callback function to the Weakref instance.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function addCallback (weakref, fn) {
|
||||
var emitter = bindings._getEmitter(weakref);
|
||||
return emitter.on(CB, fn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a weak callback function from the Weakref instance.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function removeCallback (weakref, fn) {
|
||||
var emitter = bindings._getEmitter(weakref);
|
||||
return emitter.removeListener(CB, fn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the listeners on the Weakref instance.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function callbacks (weakref) {
|
||||
var emitter = bindings._getEmitter(weakref);
|
||||
return emitter.listeners(CB);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes all callbacks on the Weakref instance.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function removeCallbacks (weakref) {
|
||||
var emitter = bindings._getEmitter(weakref);
|
||||
return emitter.removeAllListeners(CB);
|
||||
}
|
||||
|
||||
/**
|
||||
* Common weak callback function.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function callback (emitter) {
|
||||
emitter.emit(CB);
|
||||
emitter = null;
|
||||
}
|
113
node_modules/weak/package.json
generated
vendored
Normal file
113
node_modules/weak/package.json
generated
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"name": "weak",
|
||||
"raw": "weak@^1.0.0",
|
||||
"rawSpec": "^1.0.0",
|
||||
"scope": null,
|
||||
"spec": ">=1.0.0 <2.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"/root/gitbook/node_modules/dnode"
|
||||
]
|
||||
],
|
||||
"_from": "weak@>=1.0.0 <2.0.0",
|
||||
"_id": "weak@1.0.1",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/weak",
|
||||
"_nodeVersion": "5.3.0",
|
||||
"_npmUser": {
|
||||
"email": "nathan@tootallnate.net",
|
||||
"name": "tootallnate"
|
||||
},
|
||||
"_npmVersion": "3.3.12",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "weak",
|
||||
"raw": "weak@^1.0.0",
|
||||
"rawSpec": "^1.0.0",
|
||||
"scope": null,
|
||||
"spec": ">=1.0.0 <2.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/dnode"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/weak/-/weak-1.0.1.tgz",
|
||||
"_shasum": "ab99aab30706959aa0200cb8cf545bb9cb33b99e",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "weak@^1.0.0",
|
||||
"_where": "/root/gitbook/node_modules/dnode",
|
||||
"author": {
|
||||
"email": "info@bnoordhuis.nl",
|
||||
"name": "Ben Noordhuis"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/TooTallNate/node-weak/issues"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"email": "nathan@tootallnate.net",
|
||||
"name": "Nathan Rajlich",
|
||||
"url": "http://tootallnate.net"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"bindings": "^1.2.1",
|
||||
"nan": "^2.0.5"
|
||||
},
|
||||
"description": "Make weak references to JavaScript Objects.",
|
||||
"devDependencies": {
|
||||
"mocha": "~2.1.0"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"integrity": "sha512-wlbyWH3+bgtLHO0ekeAdvCYKRQJNF7sl7bKESG7PW+p5CgfEay1ChkK/d7nRXFTPvhdddwVAeXCfmxkNH3YICQ==",
|
||||
"shasum": "ab99aab30706959aa0200cb8cf545bb9cb33b99e",
|
||||
"signatures": [
|
||||
{
|
||||
"keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
|
||||
"sig": "MEYCIQCtzU+tDJ7yNN69/vFJPmvCl/Vukfpy4KKr0TFOoq23YQIhAK+KjxeHUKrKIgbm25f0HTqV/h+C8/iJrg6lI0eCFt4H"
|
||||
}
|
||||
],
|
||||
"tarball": "https://registry.npmjs.org/weak/-/weak-1.0.1.tgz"
|
||||
},
|
||||
"gitHead": "1c3b0376dab966782e5d1fcf06f9fcb1309cb2c0",
|
||||
"gypfile": true,
|
||||
"homepage": "https://github.com/TooTallNate/node-weak#readme",
|
||||
"keywords": [
|
||||
"weak",
|
||||
"reference",
|
||||
"js",
|
||||
"javascript",
|
||||
"object",
|
||||
"function",
|
||||
"callback"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "lib/weak.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"email": "nathan@tootallnate.net",
|
||||
"name": "TooTallNate"
|
||||
},
|
||||
{
|
||||
"email": "nathan@tootallnate.net",
|
||||
"name": "tootallnate"
|
||||
}
|
||||
],
|
||||
"name": "weak",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/TooTallNate/node-weak.git"
|
||||
},
|
||||
"scripts": {
|
||||
"install": "node-gyp rebuild",
|
||||
"test": "mocha -gc --reporter spec"
|
||||
},
|
||||
"version": "1.0.1"
|
||||
}
|
289
node_modules/weak/src/weakref.cc
generated
vendored
Normal file
289
node_modules/weak/src/weakref.cc
generated
vendored
Normal file
@@ -0,0 +1,289 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <nan.h>
|
||||
|
||||
using namespace v8;
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
class proxy_container {
|
||||
public:
|
||||
Nan::Persistent<Object> proxy;
|
||||
Nan::Persistent<Object> emitter;
|
||||
Nan::Persistent<Object> target;
|
||||
};
|
||||
|
||||
|
||||
Nan::Persistent<ObjectTemplate> proxyClass;
|
||||
|
||||
Nan::Callback *globalCallback;
|
||||
|
||||
|
||||
bool IsDead(Local<Object> proxy) {
|
||||
assert(proxy->InternalFieldCount() == 1);
|
||||
proxy_container *cont = reinterpret_cast<proxy_container*>(
|
||||
Nan::GetInternalFieldPointer(proxy, 0)
|
||||
);
|
||||
return cont == NULL || cont->target.IsEmpty();
|
||||
}
|
||||
|
||||
|
||||
Local<Object> Unwrap(Local<Object> proxy) {
|
||||
assert(!IsDead(proxy));
|
||||
proxy_container *cont = reinterpret_cast<proxy_container*>(
|
||||
Nan::GetInternalFieldPointer(proxy, 0)
|
||||
);
|
||||
Local<Object> _target = Nan::New<Object>(cont->target);
|
||||
return _target;
|
||||
}
|
||||
|
||||
Local<Object> GetEmitter(Local<Object> proxy) {
|
||||
proxy_container *cont = reinterpret_cast<proxy_container*>(
|
||||
Nan::GetInternalFieldPointer(proxy, 0)
|
||||
);
|
||||
assert(cont != NULL);
|
||||
Local<Object> _emitter = Nan::New<Object>(cont->emitter);
|
||||
return _emitter;
|
||||
}
|
||||
|
||||
|
||||
#define UNWRAP \
|
||||
Local<Object> obj; \
|
||||
const bool dead = IsDead(info.This()); \
|
||||
if (!dead) obj = Unwrap(info.This()); \
|
||||
|
||||
|
||||
NAN_PROPERTY_GETTER(WeakNamedPropertyGetter) {
|
||||
UNWRAP
|
||||
info.GetReturnValue().Set(dead ? Local<Value>() : Nan::Get(obj, property).ToLocalChecked());
|
||||
}
|
||||
|
||||
|
||||
NAN_PROPERTY_SETTER(WeakNamedPropertySetter) {
|
||||
UNWRAP
|
||||
if (!dead) Nan::Set(obj, property, value);
|
||||
info.GetReturnValue().Set(value);
|
||||
}
|
||||
|
||||
|
||||
NAN_PROPERTY_QUERY(WeakNamedPropertyQuery) {
|
||||
info.GetReturnValue().Set(None);
|
||||
}
|
||||
|
||||
|
||||
NAN_PROPERTY_DELETER(WeakNamedPropertyDeleter) {
|
||||
UNWRAP
|
||||
info.GetReturnValue().Set(!dead && Nan::Delete(obj, property).FromJust());
|
||||
}
|
||||
|
||||
|
||||
NAN_INDEX_GETTER(WeakIndexedPropertyGetter) {
|
||||
UNWRAP
|
||||
info.GetReturnValue().Set(dead ? Local<Value>() : Nan::Get(obj, index).ToLocalChecked());
|
||||
}
|
||||
|
||||
|
||||
NAN_INDEX_SETTER(WeakIndexedPropertySetter) {
|
||||
UNWRAP
|
||||
if (!dead) Nan::Set(obj, index, value);
|
||||
info.GetReturnValue().Set(value);
|
||||
}
|
||||
|
||||
|
||||
NAN_INDEX_QUERY(WeakIndexedPropertyQuery) {
|
||||
info.GetReturnValue().Set(None);
|
||||
}
|
||||
|
||||
|
||||
NAN_INDEX_DELETER(WeakIndexedPropertyDeleter) {
|
||||
UNWRAP
|
||||
info.GetReturnValue().Set(!dead && Nan::Delete(obj, index).FromJust());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Only one "enumerator" function needs to be defined. This function is used for
|
||||
* both the property and indexed enumerator functions.
|
||||
*/
|
||||
|
||||
NAN_PROPERTY_ENUMERATOR(WeakPropertyEnumerator) {
|
||||
UNWRAP
|
||||
info.GetReturnValue().Set(dead ? Nan::New<Array>(0) : Nan::GetPropertyNames(obj).ToLocalChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* Weakref callback function. Invokes the "global" callback function,
|
||||
* which emits the _CB event on the per-object EventEmitter.
|
||||
*/
|
||||
|
||||
static void TargetCallback(const Nan::WeakCallbackInfo<proxy_container> &info) {
|
||||
Nan::HandleScope scope;
|
||||
proxy_container *cont = info.GetParameter();
|
||||
|
||||
// invoke global callback function
|
||||
Local<Value> argv[] = {
|
||||
Nan::New<Object>(cont->emitter)
|
||||
};
|
||||
// Invoke callback directly, not via Nan::Callback->Call() which uses
|
||||
// node::MakeCallback() which calls into process._tickCallback()
|
||||
// too. Those other callbacks are not safe to run from here.
|
||||
v8::Local<v8::Function> globalCallbackDirect = globalCallback->GetFunction();
|
||||
globalCallbackDirect->Call(Nan::GetCurrentContext()->Global(), 1, argv);
|
||||
|
||||
// clean everything up
|
||||
Local<Object> proxy = Nan::New<Object>(cont->proxy);
|
||||
Nan::SetInternalFieldPointer(proxy, 0, NULL);
|
||||
cont->proxy.Reset();
|
||||
cont->emitter.Reset();
|
||||
delete cont;
|
||||
}
|
||||
|
||||
/**
|
||||
* `_create(obj, emitter)` JS function.
|
||||
*/
|
||||
|
||||
NAN_METHOD(Create) {
|
||||
if (!info[0]->IsObject()) return Nan::ThrowTypeError("Object expected");
|
||||
|
||||
proxy_container *cont = new proxy_container();
|
||||
|
||||
Local<Object> _target = info[0].As<Object>();
|
||||
Local<Object> _emitter = info[1].As<Object>();
|
||||
Local<Object> proxy = Nan::New<ObjectTemplate>(proxyClass)->NewInstance();
|
||||
cont->proxy.Reset(proxy);
|
||||
cont->emitter.Reset(_emitter);
|
||||
cont->target.Reset(_target);
|
||||
Nan::SetInternalFieldPointer(proxy, 0, cont);
|
||||
|
||||
cont->target.SetWeak(cont, TargetCallback, Nan::WeakCallbackType::kParameter);
|
||||
|
||||
info.GetReturnValue().Set(proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Make this better.
|
||||
*/
|
||||
|
||||
bool isWeakRef (Local<Value> val) {
|
||||
return val->IsObject() && val.As<Object>()->InternalFieldCount() == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* `isWeakRef()` JS function.
|
||||
*/
|
||||
|
||||
NAN_METHOD(IsWeakRef) {
|
||||
info.GetReturnValue().Set(isWeakRef(info[0]));
|
||||
}
|
||||
|
||||
#define WEAKREF_FIRST_ARG \
|
||||
if (!isWeakRef(info[0])) { \
|
||||
return Nan::ThrowTypeError("Weakref instance expected"); \
|
||||
} \
|
||||
Local<Object> proxy = info[0].As<Object>();
|
||||
|
||||
/**
|
||||
* `get(weakref)` JS function.
|
||||
*/
|
||||
|
||||
NAN_METHOD(Get) {
|
||||
WEAKREF_FIRST_ARG
|
||||
if (!IsDead(proxy))
|
||||
info.GetReturnValue().Set(Unwrap(proxy));
|
||||
}
|
||||
|
||||
/**
|
||||
* `isNearDeath(weakref)` JS function.
|
||||
*/
|
||||
|
||||
NAN_METHOD(IsNearDeath) {
|
||||
WEAKREF_FIRST_ARG
|
||||
|
||||
proxy_container *cont = reinterpret_cast<proxy_container*>(
|
||||
Nan::GetInternalFieldPointer(proxy, 0)
|
||||
);
|
||||
assert(cont != NULL);
|
||||
|
||||
Local<Boolean> rtn = Nan::New<Boolean>(cont->target.IsNearDeath());
|
||||
|
||||
info.GetReturnValue().Set(rtn);
|
||||
}
|
||||
|
||||
/**
|
||||
* `isDead(weakref)` JS function.
|
||||
*/
|
||||
|
||||
NAN_METHOD(IsDead) {
|
||||
WEAKREF_FIRST_ARG
|
||||
info.GetReturnValue().Set(IsDead(proxy));
|
||||
}
|
||||
|
||||
/**
|
||||
* `_getEmitter(weakref)` JS function.
|
||||
*/
|
||||
|
||||
NAN_METHOD(GetEmitter) {
|
||||
WEAKREF_FIRST_ARG
|
||||
info.GetReturnValue().Set(GetEmitter(proxy));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the global weak callback function.
|
||||
*/
|
||||
|
||||
NAN_METHOD(SetCallback) {
|
||||
Local<Function> callbackHandle = info[0].As<Function>();
|
||||
globalCallback = new Nan::Callback(callbackHandle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Init function.
|
||||
*/
|
||||
|
||||
NAN_MODULE_INIT(Initialize) {
|
||||
Nan::HandleScope scope;
|
||||
|
||||
Local<ObjectTemplate> p = Nan::New<ObjectTemplate>();
|
||||
proxyClass.Reset(p);
|
||||
Nan::SetNamedPropertyHandler(p,
|
||||
WeakNamedPropertyGetter,
|
||||
WeakNamedPropertySetter,
|
||||
WeakNamedPropertyQuery,
|
||||
WeakNamedPropertyDeleter,
|
||||
WeakPropertyEnumerator);
|
||||
Nan::SetIndexedPropertyHandler(p,
|
||||
WeakIndexedPropertyGetter,
|
||||
WeakIndexedPropertySetter,
|
||||
WeakIndexedPropertyQuery,
|
||||
WeakIndexedPropertyDeleter,
|
||||
WeakPropertyEnumerator);
|
||||
p->SetInternalFieldCount(1);
|
||||
|
||||
Nan::SetMethod(target, "get", Get);
|
||||
Nan::SetMethod(target, "isWeakRef", IsWeakRef);
|
||||
Nan::SetMethod(target, "isNearDeath", IsNearDeath);
|
||||
Nan::SetMethod(target, "isDead", IsDead);
|
||||
Nan::SetMethod(target, "_create", Create);
|
||||
Nan::SetMethod(target, "_getEmitter", GetEmitter);
|
||||
Nan::SetMethod(target, "_setCallback", SetCallback);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
NODE_MODULE(weakref, Initialize)
|
23
node_modules/weak/test/buffer.js
generated
vendored
Normal file
23
node_modules/weak/test/buffer.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
var assert = require('assert')
|
||||
var weak = require('../')
|
||||
|
||||
describe('weak()', function () {
|
||||
|
||||
afterEach(gc)
|
||||
|
||||
describe('Buffer', function () {
|
||||
|
||||
it('should invoke callback before destroying Buffer', function () {
|
||||
|
||||
var called = false
|
||||
weak(Buffer('test'), function (buf) {
|
||||
called = true
|
||||
})
|
||||
|
||||
assert(!called)
|
||||
gc()
|
||||
assert(called)
|
||||
})
|
||||
|
||||
})
|
||||
})
|
102
node_modules/weak/test/callback.js
generated
vendored
Normal file
102
node_modules/weak/test/callback.js
generated
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
var assert = require('assert')
|
||||
var weak = require('../')
|
||||
|
||||
describe('weak()', function () {
|
||||
|
||||
afterEach(gc)
|
||||
|
||||
describe('garbage collection callback', function () {
|
||||
|
||||
it('should accept a function as second argument', function () {
|
||||
var r = weak({}, function () {})
|
||||
assert.equal(1, weak.callbacks(r).length)
|
||||
})
|
||||
|
||||
it('should invoke the callback before the target is gc\'d', function () {
|
||||
var called = false
|
||||
weak({}, function () {
|
||||
called = true
|
||||
})
|
||||
assert(!called)
|
||||
gc()
|
||||
assert(called)
|
||||
})
|
||||
|
||||
it('should invoke *all* callbacks in the internal "callback" Array'
|
||||
, function () {
|
||||
var r = weak({})
|
||||
, called1 = false
|
||||
, called2 = false
|
||||
weak.addCallback(r, function () {
|
||||
called1 = true
|
||||
})
|
||||
weak.addCallback(r, function () {
|
||||
called2 = true
|
||||
})
|
||||
gc()
|
||||
assert(called1)
|
||||
assert(called2)
|
||||
})
|
||||
|
||||
it('should preempt code for GC callback but not nextTick callbacks'
|
||||
, function(done) {
|
||||
var calledGcCallback = false
|
||||
, calledTickCallback = false
|
||||
weak({}, function() {
|
||||
calledGcCallback = true
|
||||
})
|
||||
|
||||
process.nextTick(function() {
|
||||
calledTickCallback = true
|
||||
});
|
||||
|
||||
assert(!calledGcCallback)
|
||||
assert(!calledTickCallback)
|
||||
gc()
|
||||
assert(calledGcCallback)
|
||||
assert(!calledTickCallback)
|
||||
setTimeout(function() {
|
||||
assert(calledTickCallback);
|
||||
done();
|
||||
}, 0)
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
describe('callbacks()', function () {
|
||||
|
||||
it('should return the Weakref\'s "callback" Array', function () {
|
||||
var r = weak({}, function() {})
|
||||
, callbacks = weak.callbacks(r)
|
||||
assert(Array.isArray(callbacks))
|
||||
assert.equal(1, callbacks.length)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe('removeCallback()', function() {
|
||||
|
||||
it('removed callbacks should not be called', function() {
|
||||
var called = false
|
||||
, fn = function() { called = true }
|
||||
, r = weak({}, fn)
|
||||
weak.removeCallback(r, fn)
|
||||
gc()
|
||||
assert(!called)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe('removeCallbacks()', function() {
|
||||
|
||||
it('removed callbacks should not be called', function() {
|
||||
var called = false
|
||||
, fn = function() { called = true }
|
||||
, r = weak({}, fn)
|
||||
weak.removeCallbacks(r)
|
||||
gc()
|
||||
assert(!called)
|
||||
})
|
||||
|
||||
})
|
23
node_modules/weak/test/create.js
generated
vendored
Normal file
23
node_modules/weak/test/create.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
var assert = require('assert')
|
||||
var weak = require('../')
|
||||
|
||||
describe('create()', function () {
|
||||
|
||||
afterEach(gc)
|
||||
|
||||
it('should throw on non-"object" values', function () {
|
||||
[ 0
|
||||
, 0.0
|
||||
, true
|
||||
, false
|
||||
, null
|
||||
, undefined
|
||||
, 'foo'
|
||||
].forEach(function (val) {
|
||||
assert.throws(function () {
|
||||
weak.create(val)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
})
|
32
node_modules/weak/test/exports.js
generated
vendored
Normal file
32
node_modules/weak/test/exports.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
var assert = require('assert');
|
||||
var weak = require('../')
|
||||
|
||||
function checkFunction (prop) {
|
||||
it('should have a function "' + prop + '"', function () {
|
||||
assert('function' == typeof weak[prop]);
|
||||
})
|
||||
}
|
||||
|
||||
describe('exports', function () {
|
||||
|
||||
afterEach(gc)
|
||||
|
||||
it('should be a function', function () {
|
||||
assert('function' == typeof weak);
|
||||
})
|
||||
|
||||
checkFunction('get')
|
||||
checkFunction('create')
|
||||
checkFunction('isWeakRef')
|
||||
checkFunction('isNearDeath')
|
||||
checkFunction('isDead')
|
||||
checkFunction('callbacks')
|
||||
checkFunction('addCallback')
|
||||
checkFunction('removeCallback')
|
||||
checkFunction('removeCallbacks')
|
||||
|
||||
it('should be a circular reference to "create"', function () {
|
||||
assert(weak === weak.create);
|
||||
})
|
||||
|
||||
})
|
78
node_modules/weak/test/weakref.js
generated
vendored
Normal file
78
node_modules/weak/test/weakref.js
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
var assert = require('assert')
|
||||
var weak = require('../')
|
||||
|
||||
describe('Weakref', function () {
|
||||
|
||||
afterEach(gc)
|
||||
|
||||
it('weak() should return a `Weakref` instance', function () {
|
||||
var ref = weak({})
|
||||
assert(weak.isWeakRef(ref))
|
||||
})
|
||||
|
||||
it('should proxy named gets to the target', function () {
|
||||
var o = { foo: 'bar' }
|
||||
, r = weak(o)
|
||||
assert.equal(r.foo, 'bar')
|
||||
})
|
||||
|
||||
it('should proxy named sets to the target', function () {
|
||||
var o = {}
|
||||
, r = weak(o)
|
||||
r.foo = 'bar'
|
||||
assert.equal(r.foo, 'bar')
|
||||
})
|
||||
|
||||
it('should proxy named deletes to the target', function () {
|
||||
var o = { foo: 'bar' }
|
||||
, r = weak(o)
|
||||
delete r.foo
|
||||
assert(!r.foo)
|
||||
})
|
||||
|
||||
it('should proxy indexed gets to the target', function () {
|
||||
var a = [ 'foo' ]
|
||||
, r = weak(a)
|
||||
assert.equal(1, a.length)
|
||||
assert.equal(1, r.length)
|
||||
assert.equal('foo', r[0])
|
||||
})
|
||||
|
||||
it('should proxy indexed sets to the target', function () {
|
||||
var a = []
|
||||
, r = weak(a)
|
||||
assert.equal(0, a.length)
|
||||
assert.equal(0, r.length)
|
||||
r[0] = 'foo'
|
||||
assert.equal(1, a.length)
|
||||
assert.equal('foo', a[0])
|
||||
r.push('bar')
|
||||
assert.equal(2, a.length)
|
||||
assert.equal('bar', a[1])
|
||||
})
|
||||
|
||||
it('should proxy indexed deletes to the target', function () {
|
||||
var a = [ 'foo' ]
|
||||
, r = weak(a)
|
||||
delete r[0]
|
||||
assert.equal('undefined', typeof a[0])
|
||||
})
|
||||
|
||||
it('should proxy enumeration', function () {
|
||||
var o = { a: 'a', b: 'b', c: 'c', d: 'd' }
|
||||
, r = weak(o)
|
||||
assert.deepEqual(Object.keys(o), Object.keys(r))
|
||||
})
|
||||
|
||||
it('should act like an empty object after target is gc\'d'
|
||||
, function () {
|
||||
var o = { foo: 'bar' }
|
||||
, r = weak(o)
|
||||
o = null
|
||||
assert.equal('bar', r.foo)
|
||||
gc()
|
||||
assert(!r.foo)
|
||||
assert.equal(0,Object.keys(r).length)
|
||||
})
|
||||
|
||||
})
|
Reference in New Issue
Block a user