Fix bug where if dev passed a callback to Alloc then called AllocDispose
it wouldn't bother to pass the data to the callback and instead would
just free it.
This is a big commit that touches just about every file in the src/
directory. The V8 API has changed in significant ways. The most
important changes are:
* Binding functions take a const v8::FunctionCallbackInfo<T>& argument
rather than a const v8::Arguments& argument.
* Binding functions return void rather than v8::Handle<v8::Value>. The
return value is returned with the args.GetReturnValue().Set() family
of functions.
* v8::Persistent<T> no longer derives from v8::Handle<T> and no longer
allows you to directly dereference the object that the persistent
handle points to. This means that the common pattern of caching
oft-used JS values in a persistent handle no longer quite works,
you first need to reconstruct a v8::Local<T> from the persistent
handle with the Local<T>::New(isolate, persistent) factory method.
A handful of (internal) convenience classes and functions have been
added to make dealing with the new API a little easier.
The most visible one is node::Cached<T>, which wraps a v8::Persistent<T>
with some template sugar. It can hold arbitrary types but so far it's
exclusively used for v8::Strings (which was by far the most commonly
cached handle type.)
UsingDomains() assigned process_tickCallback when it had already
been set by MakeCallback() a few frames down the call stack.
Dispose the handle first or we'll retain whatever is in the lexical
closure of the old process._tickCallback function.
Fixes#5795.
Now that Buffer instantiation has improved, the SlabAllocator is an
unnecessary layer of complexity preventing further performance
optimizations.
Currently there is a small performance loss with very small stream
requests, but this will soon be addressed.
Most TryCatch blocks have SetVerbose flag on, this tells V8 to report
uncaught exceptions to debugger.
FatalException handler is called from V8 Message listener instead from
the place where TryCatch was used. Otherwise uncaught exceptions are
logged twice.
See comment in `deps/v8/include/v8.h` for explanation of SetVerbose
flag:
> By default, exceptions that are caught by an external exception
> handler are not reported. Call SetVerbose with true on an
> external exception handler to have exceptions caught by the
> handler reported as if they were not caught.
The flag is used by `Isolate::ShouldReportException()`, which is called
by `Isolate::DoThrow()` to decide whether an exception is considered
uncaught.
Might cause write head running over read head, when there were no
allocation and `Commit()` was called. Source of at least one test
failure on windows (`simple/test-https-drain.js`).
gcc 4.2 on OS X gets confused about the call to node::Buffer::Data().
Fully qualify the function name to help it along.
Fixes the following build error:
../../deps/v8/include/v8.h: In function ‘char*
node::Buffer::Data(v8::Handle<v8::Value>)’:
../../deps/v8/include/v8.h:900: error: ‘class v8::Data’
is not a function,
../../src/node_buffer.h:38: error:
conflict with ‘char* node::Buffer::Data(v8::Handle<v8::Object>)’
../../src/node_buffer.cc:94: error:
in call to ‘Data’
Buffer(<String>) used to pass the string to js where it would then be
passed back to cpp for processing. Now only the buffer object
instantiation is done in js and the string is processed in cpp.
Also added a Buffer api that also accepts the encoding.
Old fill would take the char code of the first character and wrap around
the int to fit in the 127 range. Now fill will duplicate whatever string
is given through the entirety of the buffer.
Note: There is one bug around ending on a partial fill of any character
outside the ASCII range.
Memory allocations are now done through smalloc. The Buffer cc class has
been removed completely, but for backwards compatibility have left the
namespace as Buffer.
The .parent attribute is only set if the Buffer is a slice of an
allocation. Which is then set to the alloc object (not a Buffer).
The .offset attribute is now a ReadOnly set to 0, for backwards
compatibility. I'd like to remove it in the future (pre v1.0).
A few alterations have been made to how arguments are either coerced or
thrown. All primitives will now be coerced to their respective values,
and (most) all out of range index requests will throw.
The indexes that are coerced were left for backwards compatibility. For
example: Buffer slice operates more like Array slice, and coerces
instead of throwing out of range indexes. This may change in the future.
The reason for wanting to throw for out of range indexes is because
giving js access to raw memory has high potential risk. To mitigate that
it's easier to make sure the developer is always quickly alerted to the
fact that their code is attempting to access beyond memory bounds.
Because SlowBuffer will be deprecated, and simply returns a new Buffer
instance, all tests on SlowBuffer have been removed.
Heapdumps will now show usage under "smalloc" instead of "Buffer".
ParseArrayIndex was added to node_internals to support proper uint
argument checking/coercion for external array data indexes.
SlabAllocator had to be updated since handle_ no longer exists.
If the user knows the allocation is no longer needed then the memory can
be manually released.
Currently this will not ClearWeak the Persistent, so the callback will
still run.
If the user passed a ClearWeak callback, and then disposed the object,
the buffer callback argument will == NULL.
smalloc is a simple utility for quickly allocating external memory onto
js objects. This will be used to centralize how memory is managed in
node, and will become the backer for Buffers. So in the future crypto's
SlabBuffer, stream's SlabAllocator will be removed.
Note on the js API: because no arguments are optional the order of
arguments have been placed to match their cc counterparts as closely as
possible.
Libuv may provide a NULL buffer to the uv_read callback in case of an
error, so with this assert we'd be using the api incorrectly. None of
the current DoRead implementations rely on this constraint, either.
Resolves minor discrepancies between android and standard POSIX systems.
In addition, some configure parameters were added, and a helper-script
for android configuration. Ideally, this script should be merged into
the standard configure script.
To build for android, source the android-configure script with an NDK
path:
source ./android-configure ~/android-ndk-r8d
This will create an android standalone toolchain and export the
necessary environment parameters.
After that, build as normal:
make -j8
After the build, you should now have android-compatible NodeJS binaries.
Suppress the following warning:
../../src/cares_wrap.cc: In function ‘v8::Handle<v8::Value>
node::cares_wrap::SetServers(const v8::Arguments&)’:
../../src/cares_wrap.cc:1017:5: warning: ‘uv_ret.uv_err_s::code’
may be used uninitialized in this function [-Wuninitialized]