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

Next #334

Closed
wants to merge 84 commits into from
Closed

Next #334

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
df3a406
Remove deprecated functions
kkoopa May 7, 2015
058fae8
Remove remnants of 0.6 compatibility
kkoopa May 8, 2015
4cf44af
Remove 0.11 compatibility
kkoopa May 8, 2015
ba9986d
WeakPersistent redesign
agnat Nov 8, 2014
b5932b4
Renamed identifiers with leading underscores
kkoopa May 1, 2015
f77b7e7
Disconnect NanScope and NanReturnValue
kkoopa Feb 10, 2015
464f1e1
Replaced NanObjectWrapHandle with class NanObjectWrap
kkoopa May 9, 2015
47751c4
Replace NanScope and NanEscpableScope macros with classes
kkoopa May 9, 2015
dd6e401
Remove NanLocker and NanUnlocker
kkoopa May 9, 2015
b5d00a9
Remove string converters, except NanUtf8String, which now follows nod…
kkoopa May 26, 2015
7fed696
Introduce NanPersistent
kkoopa May 10, 2015
4408da1
Introduce NanGlobal
kkoopa May 23, 2015
d90a25c
Remove NanReturn* macros
kkoopa May 9, 2015
4b6404a
Update for V8 v4.3
kkoopa May 23, 2015
10f1ca4
Added NanTryCatch
kkoopa May 20, 2015
c543d32
Introduce NanNewOneByteString
kkoopa May 23, 2015
6745f99
Rename NanNewBufferHandle to NanNewBuffer
kkoopa May 24, 2015
3e8b0a5
Rename NanBufferUse to NanNewBuffer
kkoopa May 24, 2015
d6af78d
Rename NanNewBuffer to NanCopyBuffer
kkoopa May 27, 2015
deaeea9
Add tests for Buffer
kkoopa May 27, 2015
5d31159
Use MaybeLocal in Buffer
kkoopa May 27, 2015
67ed1b1
Introduce namespace Nan
kkoopa May 23, 2015
594ed2a
Added version conversion script
kkoopa May 27, 2015
04da598
Emulate negative lookups
kkoopa May 29, 2015
c3cecf9
cleanup
kkoopa May 29, 2015
edfefdc
Added documentation for 1to2.js
kkoopa May 29, 2015
621bc30
Avoid duplicate warnings
kkoopa May 30, 2015
72d1f67
Remove Nan prefix from all names
kkoopa Jun 18, 2015
d5d3291
Update Buffer API for new upstream changes
kkoopa Jun 21, 2015
21a7a6a
Rename Scope and EscapableScope to HandleScope and EscapableHandleScope
kkoopa Jul 4, 2015
166ab10
Fix missing namespace in callback declaration macros
kkoopa Jul 4, 2015
1def641
Lint
kkoopa Jul 4, 2015
fc8de18
Fix bug in trycatch test
kkoopa Jul 4, 2015
f3dac47
Hide overloaded Handle variants in new versions
kkoopa Jul 4, 2015
7747fd0
Make new versions of Node use new FreeCallback
kkoopa Jul 4, 2015
3621ab6
Update the buffer-reusing constructor to return a MaybeLocal
kkoopa Jul 4, 2015
8327b6d
Fix GetFromPersistent type, which should be Value
kkoopa Jul 4, 2015
10f258d
Fix SetMethod
kkoopa Jul 13, 2015
04bd28d
Remove unused EnsureHandleOrPersistent
kkoopa Jul 13, 2015
099f81a
Remove EnsureLocal
kkoopa Jul 13, 2015
9b359f3
Remove unused Unwrap function for Maybes
kkoopa Jul 13, 2015
e8f84fe
Remove HasInstance
kkoopa Jul 13, 2015
b5b73d6
Fix Persistent stuff in ObjectWrap
kkoopa Jul 13, 2015
e6c0daf
Get rid of Handles
kkoopa Jul 20, 2015
9be6c59
minor reformat
rvagg Jul 24, 2015
0bb529d
First draft of docs for Persistent
kkoopa May 30, 2015
503df27
First draft of docs for callbacks
kkoopa May 30, 2015
f95d60d
First draft of docs for weak callbacks
kkoopa May 30, 2015
c85ebc1
First draft of docs for maybe types
kkoopa May 30, 2015
2c58265
First draft of docs for converters
kkoopa May 31, 2015
e2b0c9a
First draft of docs for asyncworker
kkoopa May 31, 2015
ef954b9
First draft of docs for nancallback
kkoopa May 31, 2015
ec953e5
docs: added initial methods & gc in methods.md
rvagg Jul 25, 2015
48f2c62
doc: added more JS-accessibe methods info
rvagg Jul 25, 2015
d6fdd4f
doc: merged callbacks.md docs into methods.md
rvagg Jul 25, 2015
e81b34b
doc: added v8_internals.md
rvagg Jul 25, 2015
b0528ad
doc: clean up and extend persistent.md
rvagg Jul 25, 2015
f380ded
doc: clean up callback.md
rvagg Jul 25, 2015
fdcfbfd
doc: clean up asyncworker.md
rvagg Jul 25, 2015
da9f6d8
doc: merge weak.md into persistent.md
rvagg Jul 25, 2015
3b4232a
doc: added WeakCallbackType (stub)
rvagg Jul 25, 2015
63fdd46
doc: further trim readme
rvagg Jul 25, 2015
fd486f4
doc: clean up converters.md
rvagg Jul 29, 2015
77d9978
doc: clean up maybe_types.md
rvagg Jul 29, 2015
fdd18ef
doc: remove news, insert TOC holder
rvagg Jul 29, 2015
854d63a
doc: add script to replace API TOC in README
rvagg Jul 29, 2015
3e890e4
doc: added errors.md
rvagg Jul 29, 2015
e85fd3c
doc: added new.md
rvagg Jul 29, 2015
91586e8
doc: added scopes.md
rvagg Jul 29, 2015
67eca52
doc: added Maybe helpers
rvagg Jul 29, 2015
80fbc0a
doc: added buffers.md
rvagg Jul 29, 2015
be73f35
added string_bytes.md
rvagg Jul 29, 2015
9f4841f
doc: added NewFromOneByte
rvagg Jul 29, 2015
b9bf5cd
doc: added script.md
rvagg Jul 29, 2015
23e8151
doc: added node_misc.md and v8_misc.md
rvagg Jul 29, 2015
b257716
doc: update readme with new apidocs, remove cruft and clean up
rvagg Jul 29, 2015
442fdc3
doc: added links to embedders guide
rvagg Jul 29, 2015
d7ad18d
doc: added Makefile 'docs' target
rvagg Jul 29, 2015
0867d34
Handle -> Local in converters.md
kkoopa Jul 30, 2015
2a97753
doc: more links and info from the V8 Embedders Guide
rvagg Jul 31, 2015
53107d9
Handle -> Local
kkoopa Jul 31, 2015
898a90a
Document WeakCallbackType
kkoopa Jul 31, 2015
9cfb390
Update example
kkoopa Jul 31, 2015
05a5826
Remove outdated porting guide
kkoopa Jul 31, 2015
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
39 changes: 36 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,42 @@ LINT_SOURCES = \
examples/async_pi_estimate/sync.cc \
examples/async_pi_estimate/sync.h \
nan.h \
nan_string_bytes.h \
nan_callbacks.h \
nan_callbacks_12_inl.h \
nan_callbacks_pre_12_inl.h \
nan_converters.h \
nan_converters_43_inl.h \
nan_converters_pre_43_inl.h \
nan_implementation_12_inl.h \
nan_implementation_pre_12_inl.h \
nan_maybe_43_inl.h \
nan_maybe_pre_43_inl.h \
nan_new.h \
nan_persistent_12_inl.h \
nan_persistent_pre_12_inl.h \
nan_string_bytes.h \
nan_weak.h \
test/cpp/accessors.cpp \
test/cpp/accessors2.cpp \
test/cpp/asyncworker.cpp \
test/cpp/asyncprogressworker.cpp \
test/cpp/asyncworkererror.cpp \
test/cpp/buffer.cpp \
test/cpp/bufferworkerpersistent.cpp \
test/cpp/error.cpp \
test/cpp/gc.cpp \
test/cpp/indexedinterceptors.cpp \
test/cpp/isolatedata.cpp \
test/cpp/makecallback.cpp \
test/cpp/morenews.cpp \
test/cpp/converters.cpp \
test/cpp/isolatedata.cpp \
test/cpp/makecallback.cpp \
test/cpp/morenews.cpp \
test/cpp/multifile1.cpp \
test/cpp/multifile2.cpp \
test/cpp/multifile2.h \
test/cpp/namedinterceptors.cpp \
test/cpp/nancallback.cpp \
test/cpp/nannew.cpp \
test/cpp/news.cpp \
Expand All @@ -41,11 +61,12 @@ LINT_SOURCES = \
test/cpp/returnundefined.cpp \
test/cpp/returnvalue.cpp \
test/cpp/settemplate.cpp \
test/cpp/settergetter.cpp \
test/cpp/strings.cpp \
test/cpp/symbols.cpp \
test/cpp/threadlocal.cpp \
test/cpp/trycatch.cpp \
test/cpp/weak.cpp \
test/cpp/weak2.cpp \
node_modules/node-gyp/gyp/data/win/large-pdb-shim.cc

FILTER = -whitespace/parens
Expand All @@ -62,5 +83,17 @@ forcetest:
cd test/ && node-gyp rebuild && cd ..
npm test

$(ADDONS): nan.h nan_string_bytes.h nan_new.h nan_implementation_pre_12_inl.h nan_implementation_12_inl.h test/binding.gyp $(SOURCES)
docs: README.md doc/.build.sh doc/asyncworker.md doc/buffers.md doc/callback.md \
doc/converters.md doc/errors.md doc/maybe_types.md doc/methods.md doc/new.md \
doc/node_misc.md doc/persistent.md doc/scopes.md doc/script.md doc/string_bytes.md \
doc/v8_internals.md doc/v8_misc.md
doc/.build.sh


$(ADDONS): nan.h nan_new.h nan_implementation_pre_12_inl.h nan_implementation_12_inl.h \
nan_callbacks.h nan_callbacks_12_inl.h nan_callbacks_pre_12_inl.h \
nan_converters.h nan_converters_43_inl.h nan_converters_pre_43_inl.h \
nan_maybe_43_inl.h nan_maybe_pre_43_inl.h \
nan_persistent_12_inl.h nan_persistent_pre_12_inl.h nan_weak.h \
nan_string_bytes.h test/binding.gyp $(SOURCES)
cd test/ && ../node_modules/.bin/node-gyp rebuild
1,417 changes: 177 additions & 1,240 deletions README.md

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions doc/.build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

files=" \
methods.md \
scopes.md \
persistent.md \
new.md \
converters.md \
maybe_types.md \
script.md \
errors.md \
buffers.md \
callback.md \
asyncworker.md \
string_bytes.md \
v8_internals.md \
v8_misc.md \
node_misc.md \
"

__dirname=$(dirname "${BASH_SOURCE[0]}")
head=$(perl -e 'while (<>) { if (!$en){print;} if ($_=~/<!-- START/){$en=1} };' $__dirname/../README.md)
tail=$(perl -e 'while (<>) { if ($_=~/<!-- END/){$st=1} if ($st){print;} };' $__dirname/../README.md)
apidocs=$(for f in $files; do
perl -pe '
last if /^<a name/;
$_ =~ s/^## /### /;
$_ =~ s/<a href="#/<a href="doc\/'$f'#/;
' $__dirname/$f;
done)

cat > $__dirname/../README.md << EOF
$head

$apidocs

$tail
EOF
97 changes: 97 additions & 0 deletions doc/asyncworker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
## Asynchronous work helpers

`Nan::AsyncWorker` and `Nan::AsyncProgressWorker` are helper classes that make working with asynchronous code easier.

- <a href="#api_nan_async_worker"><b><code>Nan::AsyncWorker</code></b></a>
- <a href="#api_nan_async_progress_worker"><b><code>Nan::AsyncProgressWorker</code></b></a>
- <a href="#api_nan_async_queue_worker"><b><code>Nan::AsyncQueueWorker</code></b></a>

<a name="api_nan_async_worker"></a>
### Nan::AsyncWorker

`Nan::AsyncWorker` is an _abstract_ class that you can subclass to have much of the annoying asynchronous queuing and handling taken care of for you. It can even store arbitrary V8 objects for you and have them persist while the asynchronous work is in progress.

Definition:

```c++
class AsyncWorker {
public:
explicit AsyncWorker(Callback *callback_);

virtual ~AsyncWorker();

virtual void WorkComplete();

void SaveToPersistent(const char *key, const v8::Local<v8::Value> &value);

void SaveToPersistent(const v8::Local<v8::String> &key,
const v8::Local<v8::Value> &value);

void SaveToPersistent(uint32_t index,
const v8::Local<v8::Value> &value);

v8::Local<v8::Value> GetFromPersistent(const char *key) const;

v8::Local<v8::Value> GetFromPersistent(const v8::Local<v8::String> &key) const;

v8::Local<v8::Value> GetFromPersistent(uint32_t index) const;

virtual void Execute() = 0;

uv_work_t request;

virtual void Destroy();

protected:
Persistent<v8::Object> persistentHandle;

Callback *callback;

virtual void HandleOKCallback();

virtual void HandleErrorCallback();

void SetErrorMessage(const char *msg);

const char* ErrorMessage();
};
```

<a name="api_nan_async_progress_worker"></a>
### Nan::AsyncProgressWorker

`Nan::AsyncProgressWorker` is an _abstract_ class that extends `Nan::AsyncWorker` and adds additional progress reporting callbacks that can be used during the asynchronous work execution to provide progress data back to JavaScript.

Definition:

```c++
class AsyncProgressWorker : public AsyncWorker {
public:
explicit AsyncProgressWorker(Callback *callback_);

virtual ~AsyncProgressWorker();

void WorkProgress();

class ExecutionProgress {
public:
void Send(const char* data, size_t size) const;
};

virtual void Execute(const ExecutionProgress& progress) = 0;

virtual void HandleProgressCallback(const char *data, size_t size) = 0;

virtual void Destroy();
```

<a name="api_nan_async_queue_worker"></a>
### Nan::AsyncQueueWorker

`Nan::AsyncQueueWorker` will run a `Nan::AsyncWorker` asynchronously via libuv. Both the `execute` and `after_work` steps are taken care of for you. Most of the logic for this is embedded in `Nan::AsyncWorker`.

Definition:

```c++
void AsyncQueueWorker(AsyncWorker *);
```
40 changes: 40 additions & 0 deletions doc/buffers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Buffers

NAN's `node::Buffer` helpers exist as the API has changed across supported Node versions. Use these methods to ensure compatibility.

- <a href="#api_nan_new_buffer"><b><code>Nan::NewBuffer()</code></b></a>
- <a href="#api_nan_copy_buffer"><b><code>Nan::CopyBuffer()</code></b></a>


<a name="api_nan_new_buffer"></a>
### Nan::NewBuffer()

Allocate a new `node::Buffer` object with the specified size and optional data. Calls `node::Buffer::New()`.

Note that when creating a `Buffer` using `Nan::NewBuffer()` and an existing `char*`, it is assumed that the ownership of the pointer is being transferred to the new `Buffer` for management. You _must not_ free the memory space manually once you have created a `Buffer` in this way.

Signature:

```c++
Nan::MaybeLocal<v8::Object> Nan::NewBuffer(uint32_t size)
Nan::MaybeLocal<v8::Object> Nan::NewBuffer(char* data, uint32_t size)
// uses `node::smalloc::FreeCallback` on older versions of Node
Nan::MaybeLocal<v8::Object> Nan::NewBuffer(char *data,
size_t length,
node::Buffer::FreeCallback callback,
void *hint)
```


<a name="api_nan_copy_buffer"></a>
### Nan::CopyBuffer()

Similar to [`Nan::NewBuffer()`](#api_nan_new_buffer) except that an implicit memcpy will occur within Node. Calls `node::Buffer::Copy()`.

Management of the `char*` is left to the user, you should manually free the memory space if necessary as the new `Buffer` will have its own copy.

Signature:

```c++
Nan::MaybeLocal<v8::Object> Nan::CopyBuffer(const char *data, uint32_t size)
```
52 changes: 52 additions & 0 deletions doc/callback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
## Nan::Callback

`Nan::Callback` makes it easier to use `v8::Function` handles as callbacks. A class that wraps a `v8::Function` handle, protecting it from garbage collection and making it particularly useful for storage and use across asynchronous execution.

- <a href="#api_nan_callback"><b><code>Nan::Callback</code></b></a>

<a name="api_nan_callback"></a>
### Nan::Callback

```c++
class Callback {
public:
Callback();

explicit Callback(const v8::Local<v8::Function> &fn);

~Callback();

bool operator==(const Callback &other) const;

bool operator!=(const Callback &other) const;

v8::Local<v8::Function> operator*() const;

v8::Local<v8::Value> operator()(v8::Local<v8::Object> target,
int argc = 0,
v8::Local<v8::Value> argv[] = 0) const;

v8::Local<v8::Value> operator()(int argc = 0,
v8::Local<v8::Value> argv[] = 0) const;

void SetFunction(const v8::Local<v8::Function> &fn);

v8::Local<v8::Function> GetFunction() const;

bool IsEmpty() const;

v8::Local<v8::Value> Call(v8::Local<v8::Object> target,
int argc,
v8::Local<v8::Value> argv[]) const;

v8::Local<v8::Value> Call(int argc, v8::Local<v8::Value> argv[]) const;
};
```

Example usage:

```c++
v8::Local<v8::Function> function;
Nan::Callback callback(function);
callback->Call(0, 0);
```
41 changes: 41 additions & 0 deletions doc/converters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## Converters

NAN contains functions that convert `v8::Value`s to other `v8::Value` types and native types. Since type conversion is not guaranteed to succeed, they return `Nan::Maybe` types. These converters can be used in place of `value->ToX()` and `value->XValue()` (where `X` is one of the types, e.g. `Boolean`) in a way that provides a consistent interface across V8 versions. Newer versions of V8 use the new `v8::Maybe` and `v8::MaybeLocal` types for these conversions, older versions don't have this functionality so it is provided by NAN.

- <a href="#api_nan_to"><b><code>Nan::To</code></b></a>

<a name="api_nan_to"></a>
### Nan::To

Converts a `v8::Local<v8::Value>` to a different subtype of `v8::Value` or to a native data type. Returns a `Nan::MaybeLocal<>` or a `Nan::Maybe<>` accordingly.

See [maybe_types.md](./maybe_types.md) for more information on `Nan::Maybe` types.

Signatures:

```c++
// V8 types
Nan::MaybeLocal<v8::Boolean> Nan::To<v8::Boolean>(v8::Local<v8::Value> val);
Nan::MaybeLocal<v8::Int32> Nan::To<v8::Int32>(v8::Local<v8::Value> val);
Nan::MaybeLocal<v8::Integer> Nan::To<v8::Integer>(v8::Local<v8::Value> val);
Nan::MaybeLocal<v8::Object> Nan::To<v8::Object>(v8::Local<v8::Value> val);
Nan::MaybeLocal<v8::Number> Nan::To<v8::Number>(v8::Local<v8::Value> val);
Nan::MaybeLocal<v8::String> Nan::To<v8::String>(v8::Local<v8::Value> val);
Nan::MaybeLocal<v8::Uint32> Nan::To<v8::Uint32>(v8::Local<v8::Value> val);

// Native types
Nan::Maybe<bool> Nan::To<bool>(v8::Local<v8::Value> val);
Nan::Maybe<double> Nan::To<double>(v8::Local<v8::Value> val);
Nan::Maybe<int32_t> Nan::To<int32_t>(v8::Local<v8::Value> val);
Nan::Maybe<int64_t> Nan::To<int64_t>(v8::Local<v8::Value> val);
Nan::Maybe<uint32_t> Nan::To<uint32_t>(v8::Local<v8::Value> val);
```

### Example

```c++
v8::Local<v8::Value> val;
Nan::MaybeLocal<v8::String> str = Nan::To<v8::String>(val);
Nan::Maybe<double> d = Nan::To<double>(val);
```

Loading