diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2013-07-03 04:23:44 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2013-07-06 17:44:44 +0200 |
commit | 110a9cd8db515c4d1a9ac5cd8837291da7c6c5ea (patch) | |
tree | 71e5a14a98131d89d670f842eb36bfcccab00b7b /src/tty_wrap.cc | |
parent | 9b3de60d3537df657e75887436a5b1df5ed80c2d (diff) | |
download | android-node-v8-110a9cd8db515c4d1a9ac5cd8837291da7c6c5ea.tar.gz android-node-v8-110a9cd8db515c4d1a9ac5cd8837291da7c6c5ea.tar.bz2 android-node-v8-110a9cd8db515c4d1a9ac5cd8837291da7c6c5ea.zip |
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.)
Diffstat (limited to 'src/tty_wrap.cc')
-rw-r--r-- | src/tty_wrap.cc | 77 |
1 files changed, 24 insertions, 53 deletions
diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index 182a26028f..457a3e8783 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -29,18 +29,16 @@ namespace node { -using v8::Arguments; using v8::Function; +using v8::FunctionCallbackInfo; using v8::FunctionTemplate; using v8::Handle; using v8::HandleScope; using v8::Integer; using v8::Local; using v8::Object; -using v8::Persistent; using v8::PropertyAttribute; using v8::String; -using v8::Undefined; using v8::Value; @@ -80,8 +78,7 @@ void TTYWrap::Initialize(Handle<Object> target) { NODE_SET_METHOD(target, "isTTY", IsTTY); NODE_SET_METHOD(target, "guessHandleType", GuessHandleType); - ttyConstructorTmpl = Persistent<FunctionTemplate>::New(node_isolate, t); - + ttyConstructorTmpl.Reset(node_isolate, t); target->Set(String::NewSymbol("TTY"), t->GetFunction()); } @@ -98,89 +95,66 @@ uv_tty_t* TTYWrap::UVHandle() { } -Handle<Value> TTYWrap::GuessHandleType(const Arguments& args) { +void TTYWrap::GuessHandleType(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); int fd = args[0]->Int32Value(); assert(fd >= 0); uv_handle_type t = uv_guess_handle(fd); + const char* type = NULL; switch (t) { - case UV_TCP: - return scope.Close(String::New("TCP")); - - case UV_TTY: - return scope.Close(String::New("TTY")); - - case UV_UDP: - return scope.Close(String::New("UDP")); - - case UV_NAMED_PIPE: - return scope.Close(String::New("PIPE")); - - case UV_FILE: - return scope.Close(String::New("FILE")); - - case UV_UNKNOWN_HANDLE: - return scope.Close(String::New("UNKNOWN")); - - default: - assert(0); - return v8::Undefined(node_isolate); + case UV_TCP: type = "TCP"; break; + case UV_TTY: type = "TTY"; break; + case UV_UDP: type = "UDP"; break; + case UV_FILE: type = "FILE"; break; + case UV_NAMED_PIPE: type = "PIPE"; break; + case UV_UNKNOWN_HANDLE: type = "UNKNOWN"; break; + default: + abort(); } + + args.GetReturnValue().Set(String::New(type)); } -Handle<Value> TTYWrap::IsTTY(const Arguments& args) { +void TTYWrap::IsTTY(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); int fd = args[0]->Int32Value(); assert(fd >= 0); - - if (uv_guess_handle(fd) == UV_TTY) { - return v8::True(node_isolate); - } - - return v8::False(node_isolate); + bool rc = uv_guess_handle(fd) == UV_TTY; + args.GetReturnValue().Set(rc); } -Handle<Value> TTYWrap::GetWindowSize(const Arguments& args) { +void TTYWrap::GetWindowSize(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); UNWRAP(TTYWrap) int width, height; int r = uv_tty_get_winsize(&wrap->handle_, &width, &height); - - if (r) { - SetErrno(uv_last_error(uv_default_loop())); - return v8::Undefined(node_isolate); - } + if (r) return SetErrno(uv_last_error(uv_default_loop())); Local<v8::Array> a = v8::Array::New(2); a->Set(0, Integer::New(width, node_isolate)); a->Set(1, Integer::New(height, node_isolate)); - - return scope.Close(a); + args.GetReturnValue().Set(a); } -Handle<Value> TTYWrap::SetRawMode(const Arguments& args) { +void TTYWrap::SetRawMode(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); UNWRAP(TTYWrap) int r = uv_tty_set_mode(&wrap->handle_, args[0]->IsTrue()); - - if (r) { - SetErrno(uv_last_error(uv_default_loop())); - } - - return scope.Close(Integer::New(r, node_isolate)); + if (r) SetErrno(uv_last_error(uv_default_loop())); + args.GetReturnValue().Set(r); } -Handle<Value> TTYWrap::New(const Arguments& args) { +void TTYWrap::New(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); // This constructor should not be exposed to public javascript. @@ -192,10 +166,7 @@ Handle<Value> TTYWrap::New(const Arguments& args) { assert(fd >= 0); TTYWrap* wrap = new TTYWrap(args.This(), fd, args[1]->IsTrue()); - assert(wrap); wrap->UpdateWriteQueueSize(); - - return scope.Close(args.This()); } |