summaryrefslogtreecommitdiff
path: root/src/node_http_parser.cc
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2013-09-25 12:57:03 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2013-09-25 19:44:53 +0200
commitc79d5163e530892c62b08d8b814b588220c26ec8 (patch)
tree771823ddf0dac11efe378f8ddc6ddcd0e756a0f0 /src/node_http_parser.cc
parent42af62f33adda57d8913768d939c1f4d0f8fe5a3 (diff)
downloadandroid-node-v8-c79d5163e530892c62b08d8b814b588220c26ec8.tar.gz
android-node-v8-c79d5163e530892c62b08d8b814b588220c26ec8.tar.bz2
android-node-v8-c79d5163e530892c62b08d8b814b588220c26ec8.zip
src: remove ObjectWrap dependency from core
Drop the ObjectWrap dependency in favor of an internal WeakObject class. Let's us stop worrying about API and ABI compatibility when making changes to the way node.js deals with weakly persistent handles internally.
Diffstat (limited to 'src/node_http_parser.cc')
-rw-r--r--src/node_http_parser.cc27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc
index 80046a9b7b..8118091180 100644
--- a/src/node_http_parser.cc
+++ b/src/node_http_parser.cc
@@ -25,6 +25,8 @@
#include "env.h"
#include "env-inl.h"
+#include "weak-object.h"
+#include "weak-object-inl.h"
#include "v8.h"
#include <stdlib.h> // free()
@@ -185,10 +187,10 @@ struct StringPtr {
};
-class Parser : public ObjectWrap {
+class Parser : public WeakObject {
public:
- Parser(Environment* env, enum http_parser_type type)
- : ObjectWrap()
+ Parser(Environment* env, Local<Object> wrap, enum http_parser_type type)
+ : WeakObject(env->isolate(), wrap)
, env_(env)
, current_buffer_len_(0)
, current_buffer_data_(NULL) {
@@ -252,7 +254,7 @@ class Parser : public ObjectWrap {
HTTP_CB(on_headers_complete) {
- Local<Object> obj = handle(node_isolate);
+ Local<Object> obj = weak_object(node_isolate);
Local<Value> cb = obj->Get(kOnHeadersComplete);
if (!cb->IsFunction())
@@ -313,7 +315,7 @@ class Parser : public ObjectWrap {
HTTP_DATA_CB(on_body) {
HandleScope scope(node_isolate);
- Local<Object> obj = handle(node_isolate);
+ Local<Object> obj = weak_object(node_isolate);
Local<Value> cb = obj->Get(kOnBody);
if (!cb->IsFunction())
@@ -342,7 +344,7 @@ class Parser : public ObjectWrap {
if (num_fields_)
Flush(); // Flush trailing HTTP headers.
- Local<Object> obj = handle(node_isolate);
+ Local<Object> obj = weak_object(node_isolate);
Local<Value> cb = obj->Get(kOnMessageComplete);
if (!cb->IsFunction())
@@ -362,13 +364,10 @@ class Parser : public ObjectWrap {
static void New(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope handle_scope(args.GetIsolate());
-
http_parser_type type =
static_cast<http_parser_type>(args[0]->Int32Value());
-
assert(type == HTTP_REQUEST || type == HTTP_RESPONSE);
- Parser* parser = new Parser(env, type);
- parser->Wrap(args.This());
+ new Parser(env, args.This(), type);
}
@@ -389,7 +388,7 @@ class Parser : public ObjectWrap {
static void Execute(const FunctionCallbackInfo<Value>& args) {
HandleScope scope(node_isolate);
- Parser* parser = ObjectWrap::Unwrap<Parser>(args.This());
+ Parser* parser = WeakObject::Unwrap<Parser>(args.This());
assert(parser->current_buffer_.IsEmpty());
assert(parser->current_buffer_len_ == 0);
assert(parser->current_buffer_data_ == NULL);
@@ -443,7 +442,7 @@ class Parser : public ObjectWrap {
static void Finish(const FunctionCallbackInfo<Value>& args) {
HandleScope scope(node_isolate);
- Parser* parser = ObjectWrap::Unwrap<Parser>(args.This());
+ Parser* parser = WeakObject::Unwrap<Parser>(args.This());
assert(parser->current_buffer_.IsEmpty());
parser->got_exception_ = false;
@@ -476,7 +475,7 @@ class Parser : public ObjectWrap {
static_cast<http_parser_type>(args[0]->Int32Value());
assert(type == HTTP_REQUEST || type == HTTP_RESPONSE);
- Parser* parser = ObjectWrap::Unwrap<Parser>(args.This());
+ Parser* parser = WeakObject::Unwrap<Parser>(args.This());
// Should always be called from the same context.
assert(env == parser->env());
parser->Init(type);
@@ -503,7 +502,7 @@ class Parser : public ObjectWrap {
void Flush() {
HandleScope scope(node_isolate);
- Local<Object> obj = handle(node_isolate);
+ Local<Object> obj = weak_object(node_isolate);
Local<Value> cb = obj->Get(kOnHeaders);
if (!cb->IsFunction())