Commit Graph

100 Commits

Author SHA1 Message Date
Trevor Norris
4a9af3fecb async_wrap: add provider types/pass to constructor
These will be used to allow users to filter for which types of calls
they wish their callbacks to run.

Signed-off-by: Timothy J Fontaine <tjfontaine@gmail.com>
2014-02-05 13:30:56 -08:00
Keith M Wesolowski
76b98462e5 node: register modules from DSO constructors
Built-in modules should be automatically registered, replacing the
static module list.  Add-on modules should also be automatically
registered via DSO constructors.  This improves flexibility in adding
built-in modules and is also a prerequisite to pure-C addon modules.
2014-01-27 15:52:50 -08:00
Ben Noordhuis
27f115d715 src: fix Context::Scope usage
env->context() may or may not create a new Local.  It currently does
not but don't depend on that behavior, create a HandleScope first.
2013-11-12 22:06:48 +01:00
Ben Noordhuis
09724b311e src: fix Environment::GetCurrent() usage
Create a HandleScope before calling the Environment::GetCurrent() that
takes a v8::Isolate* as an argument because it creates a handle with
the call to v8::Isolate::CurrentContext().
2013-11-11 10:40:28 +01:00
Trevor Norris
efa62fd9cc node: add AsyncListener support
AsyncListener is a JS API that works in tandem with the AsyncWrap class
to allow the user to be alerted to key events in the life cycle of an
asynchronous event. The AsyncWrap class has its own MakeCallback
implementation that core will be migrated to use, and uses state sharing
techniques to allow quicker communication between JS and C++ whether the
async event callbacks need to be called.
2013-10-31 14:17:51 -07:00
Trevor Norris
613d76ef6a src: shorten Object{Wrap,Unwrap}
Going back to the original names of Wrap/Unwrap now that most all the
class members that duplicate the name and functionality have been
removed.
2013-10-29 15:09:44 -07:00
Trevor Norris
93f75a86bf src: use function to get internal pointer
Remove the NODE_{WRAP,UNWRAP} macros and instead use template functions.
2013-10-29 15:09:44 -07:00
Ben Noordhuis
756b622295 src: add multi-context support
This commit makes it possible to use multiple V8 execution contexts
within a single event loop.  Put another way, handle and request wrap
objects now "remember" the context they belong to and switch back to
that context when the time comes to call into JS land.

This could have been done in a quick and hacky way by calling
v8::Object::GetCreationContext() on the wrap object right before
making a callback but that leaves a fairly wide margin for bugs.

Instead, we make the context explicit through a new Environment class
that encapsulates everything (or almost everything) that belongs to
the context.  Variables that used to be a static or a global are now
members of the aforementioned class.  An additional benefit is that
this approach should make it relatively straightforward to add full
isolate support in due course.

There is no JavaScript API yet but that will be added in the near
future.

This work was graciously sponsored by GitHub, Inc.
2013-09-06 05:51:42 +02:00
Timothy J Fontaine
93b062468b timer_wrap: Timer.now always update loop time
In `Timer.now` always update the loop time by calling uv_update_time.
Previously we were trying to cache the loop time to prevent extra
syscalls. While a noble goal, it can cause timers to fire early in
certain circumstances. Especially seen in cpu bound work loads or work
loads with synchronous file operations.
2013-08-28 11:29:33 -07:00
Ben Noordhuis
9fc006618f src: fix up unused/unordered imports 2013-08-27 00:13:50 +02:00
Ben Noordhuis
0aa13357d6 timers: dispatch ontimeout callback by array index
Achieve a minor speed-up by looking up the timeout callback on the timer
object by using an array index rather than a named property.

Gives a performance boost of about 1% on the misc/timers benchmarks.
2013-08-15 19:33:34 +02:00
Trevor Norris
35f789b027 src: fix build break from generic macro name
WRAP is too generic a macro name and causes the build to fail from
conflicts. They have been prepended with NODE_.
2013-08-12 12:54:49 -07:00
Trevor Norris
756ae2c536 src: centralize class wrap/unwrap
While almost all cases were handled by simple WRAP/UNWRAP macros, this
extends those to cover all known occurrences.
2013-08-12 11:49:53 -07:00
Ben Noordhuis
f674b09f40 src: use v8::String::NewFrom*() functions
* Change calls to String::New() and String::NewSymbol() to their
  respective one-byte, two-byte and UTF-8 counterparts.

* Add a FIXED_ONE_BYTE_STRING macro that takes a string literal and
  turns it into a v8::Local<v8::String>.

* Add helper functions that make v8::String::NewFromOneByte() easier to
  work with. Said function expects a `const uint8_t*` but almost every
  call site deals with `const char*` or `const unsigned char*`. Helps
  us avoid doing reinterpret_casts all over the place.

* Code that handles file system paths keeps using UTF-8 for backwards
  compatibility reasons. At least now the use of UTF-8 is explicit.

* Remove v8::String::NewSymbol() entirely. Almost all call sites were
  effectively minor de-optimizations. If you create a string only once,
  there is no point in making it a symbol. If you are create the same
  string repeatedly, it should probably be cached in a persistent
  handle.
2013-08-09 11:44:50 +02:00
Ben Noordhuis
d24decb87b src: remove no-op HandleWrap::Initialize()
It's never been used and we probably never will. Remove it.
2013-08-07 18:03:14 +02:00
Fedor Indutny
8e29ce9f13 src: lint c++ code 2013-07-31 22:12:06 +04:00
Ben Noordhuis
ca9eb718fb src, lib: update after internal api change
Libuv now returns errors directly.  Make everything in src/ and lib/
follow suit.

The changes to lib/ are not strictly necessary but they remove the need
for the abominations that are process._errno and node::SetErrno().
2013-07-20 12:09:29 +02:00
Ben Noordhuis
110a9cd8db lib, src: upgrade after v8 api change
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.)
2013-07-06 17:44:44 +02:00
Ben Noordhuis
b9165252e3 src: clean up using directives
Remove the unused ones and alphabetically sort the ones that remain.
2013-06-17 23:32:19 +02:00
Ben Noordhuis
448adaa456 src: simplify HandleWrap initialization 2013-05-30 00:12:49 +02:00
Ben Noordhuis
4d68daea0f src: replace c-style casts with c++-style casts 2013-05-30 00:12:49 +02:00
Timothy J Fontaine
f8193ab3c4 timers: use uv_now instead of Date.now
This saves a few calls to gettimeofday which can be expensive, and
potentially subject to clock drift. Instead use the loop time which
uses hrtime internally.

fixes #5497
2013-05-22 20:13:14 -07:00
Trevor Norris
f65e14ed1d src: pass Isolate to all applicable api
Update the api to pass node_isolate to all supported methods.

Much thanks to Ben Noordhuis and his work in 51f6e6a.
2013-03-20 01:11:02 +01:00
Ben Noordhuis
51f6e6a9b3 src, test: downgrade to v8 3.14 api 2013-02-25 23:45:02 +01:00
Ben Noordhuis
6573fc3502 src: pass node_isolate to Integer::New 2013-01-07 17:39:57 +01:00
Timothy J Fontaine
19d43f852e export HandleWrap Unref Ref in tcp/udp/timer/pipe 2012-07-23 18:31:29 +02:00
Ben Noordhuis
039fac633e deps: upgrade libuv to a478847
The event loop's reference counting scheme in this version of libuv has changed.
Update the libuv bindings to reflect that fact.
2012-05-22 16:14:24 +02:00
Oleg Efimov
45de259b43 Make UNWRAP macro generic. 2012-05-21 23:29:06 +02:00
isaacs
a26bee8fa1 MakeCallback: Consistent symbol usage 2012-04-17 13:14:54 -07:00
Ben Noordhuis
ff4a9d381d core: use proper #include directives 2012-03-10 00:14:14 +01:00
Ben Noordhuis
74a8215a86 Revert support for isolates.
It was decided that the performance benefits that isolates offer (faster spin-up
times for worker processes, faster inter-worker communication, possibly a lower
memory footprint) are not actual bottlenecks for most people and do not outweigh
the potential stability issues and intrusive changes to the code base that
first-class support for isolates requires.

Hence, this commit backs out all isolates-related changes.

Good bye, isolates. We hardly knew ye.
2012-02-06 15:44:42 +01:00
Ryan Dahl
20ba454ef9 Add node::Loop() and don't inc node_isolate.h in *.cc
node::Loop() replaces the NODE_LOOP macro. This avoids hitting
v8::Isolate::GetCurrent() for each loop lookup when HAVE_ISOLATE==0
2011-12-29 01:56:11 +01:00
Ryan Dahl
f168f7d702 Remove node_isolate.h from node.h 2011-12-29 01:56:10 +01:00
Ben Noordhuis
356992fe4d isolates: isolate-ify the main loop 2011-12-29 01:56:09 +01:00
Ben Noordhuis
cdcb1118c8 Remove stray NODE_MODULE() semi-colons. 2011-11-09 16:34:09 +01:00
Ryan Dahl
60818b957c Add missing copyright headers 2011-11-02 10:00:57 -07:00
Ryan Dahl
6cc42927d8 Display sys_errno when UV_UNKNOWN is returned 2011-10-19 16:53:07 -07:00
Ben Noordhuis
87b34c94fa timer_wrap: add sanity check assert 2011-10-14 15:01:26 +00:00
Ryan Dahl
21cc4c4985 Upgrade libuv to ea4271f
Required adding uv_default_loop() in many places.
2011-08-31 01:53:30 -07:00
Ryan Dahl
85404c5c55 Move HandleWrap rules to one place 2011-07-18 13:47:56 -07:00
Ryan Dahl
0c7bf8132e Abstract out HandleWrap class 2011-07-18 04:22:16 -07:00
Henry Rawas
47a5d93256 Fix test-net-pingpong.js on windows 2011-06-28 13:52:36 +02:00
Ryan Dahl
f657d58fe1 Upgrade libuv to f9b9bb44bd6e2b74729b5d1ff481adf4213e9a0b 2011-06-28 13:37:03 +02:00
Ryan Dahl
1261b17129 libuv wraps: Dispose of JS object on close() 2011-06-14 13:03:49 +02:00
Ryan Dahl
623f513071 Upgrade libuv 2011-06-10 18:17:44 +02:00
Bert Belder
d9aa9b54cf Use timer_wrap instead of the old timer binding 2011-06-08 05:06:13 +02:00
Ryan Dahl
7a5977b5d6 Upgrade libuv to e58a1abff02d7bacf89a56de9050e27690a97bc5 2011-06-07 18:59:44 +02:00
Ryan Dahl
650a308634 Move MakeCallback and SetErrno to node.cc 2011-05-28 13:44:03 -07:00
Ryan Dahl
4d22405f0f TimerWrap: mimic libev ref count semantics 2011-05-28 13:21:03 -07:00
Ryan Dahl
9d1bad8960 Implement new wrap for uv timer 2011-05-25 10:17:02 -07:00