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/node_zlib.cc | |
parent | 9b3de60d3537df657e75887436a5b1df5ed80c2d (diff) | |
download | node-new-110a9cd8db515c4d1a9ac5cd8837291da7c6c5ea.tar.gz |
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/node_zlib.cc')
-rw-r--r-- | src/node_zlib.cc | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/src/node_zlib.cc b/src/node_zlib.cc index 9bfc33e580..07f44d126e 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -32,11 +32,20 @@ namespace node { -using namespace v8; +using v8::FunctionCallbackInfo; +using v8::FunctionTemplate; +using v8::Handle; +using v8::HandleScope; +using v8::Integer; +using v8::Local; +using v8::Number; +using v8::Object; +using v8::String; +using v8::Value; -static Persistent<String> callback_sym; -static Persistent<String> onerror_sym; +static Cached<String> callback_sym; +static Cached<String> onerror_sym; enum node_zlib_mode { NONE, @@ -104,16 +113,15 @@ class ZCtx : public ObjectWrap { } - static Handle<Value> Close(const Arguments& args) { + static void Close(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); ZCtx *ctx = ObjectWrap::Unwrap<ZCtx>(args.This()); ctx->Close(); - return scope.Close(Undefined(node_isolate)); } // write(flush, in, in_off, in_len, out, out_off, out_len) - static Handle<Value> Write(const Arguments& args) { + static void Write(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); assert(args.Length() == 7); @@ -183,7 +191,7 @@ class ZCtx : public ObjectWrap { ZCtx::Process, ZCtx::After); - return ctx->handle_; + args.GetReturnValue().Set(ctx->persistent()); } @@ -273,10 +281,10 @@ class ZCtx : public ObjectWrap { ctx->write_in_progress_ = false; // call the write() cb - assert(ctx->handle_->Get(callback_sym)->IsFunction() && - "Invalid callback"); + Local<Object> handle = ctx->handle(node_isolate); + assert(handle->Get(callback_sym)->IsFunction() && "Invalid callback"); Local<Value> args[2] = { avail_in, avail_out }; - MakeCallback(ctx->handle_, callback_sym, ARRAY_SIZE(args), args); + MakeCallback(handle, callback_sym, ARRAY_SIZE(args), args); ctx->Unref(); } @@ -289,37 +297,37 @@ class ZCtx : public ObjectWrap { msg = msg_; } - assert(ctx->handle_->Get(onerror_sym)->IsFunction() && - "Invalid error handler"); + Local<Object> handle = ctx->handle(node_isolate); + assert(handle->Get(onerror_sym)->IsFunction() && "Invalid error handler"); HandleScope scope(node_isolate); - Local<Value> args[2] = { String::New(msg), - Local<Value>::New(node_isolate, - Number::New(ctx->err_)) }; - MakeCallback(ctx->handle_, onerror_sym, ARRAY_SIZE(args), args); + Local<Value> args[2] = { + String::New(msg), + Number::New(ctx->err_) + }; + MakeCallback(handle, onerror_sym, ARRAY_SIZE(args), args); // no hope of rescue. ctx->write_in_progress_ = false; ctx->Unref(); } - static Handle<Value> New(const Arguments& args) { + static void New(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); if (args.Length() < 1 || !args[0]->IsInt32()) { - return ThrowException(Exception::TypeError(String::New("Bad argument"))); + return ThrowTypeError("Bad argument"); } node_zlib_mode mode = (node_zlib_mode) args[0]->Int32Value(); if (mode < DEFLATE || mode > UNZIP) { - return ThrowException(Exception::TypeError(String::New("Bad argument"))); + return ThrowTypeError("Bad argument"); } ZCtx *ctx = new ZCtx(mode); ctx->Wrap(args.This()); - return args.This(); } // just pull the ints out of the args and call the other Init - static Handle<Value> Init(const Arguments& args) { + static void Init(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); assert((args.Length() == 4 || args.Length() == 5) && @@ -357,10 +365,9 @@ class ZCtx : public ObjectWrap { Init(ctx, level, windowBits, memLevel, strategy, dictionary, dictionary_len); SetDictionary(ctx); - return Undefined(node_isolate); } - static Handle<Value> Params(const Arguments& args) { + static void Params(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); assert(args.Length() == 2 && "params(level, strategy)"); @@ -368,18 +375,15 @@ class ZCtx : public ObjectWrap { ZCtx* ctx = ObjectWrap::Unwrap<ZCtx>(args.This()); Params(ctx, args[0]->Int32Value(), args[1]->Int32Value()); - - return Undefined(node_isolate); } - static Handle<Value> Reset(const Arguments &args) { + static void Reset(const FunctionCallbackInfo<Value> &args) { HandleScope scope(node_isolate); ZCtx *ctx = ObjectWrap::Unwrap<ZCtx>(args.This()); Reset(ctx); SetDictionary(ctx); - return Undefined(node_isolate); } static void Init(ZCtx *ctx, int level, int windowBits, int memLevel, @@ -549,8 +553,8 @@ void InitZlib(Handle<Object> target) { z->SetClassName(String::NewSymbol("Zlib")); target->Set(String::NewSymbol("Zlib"), z->GetFunction()); - callback_sym = NODE_PSYMBOL("callback"); - onerror_sym = NODE_PSYMBOL("onerror"); + callback_sym = String::New("callback"); + onerror_sym = String::New("onerror"); // valid flush values. NODE_DEFINE_CONSTANT(target, Z_NO_FLUSH); |