Skip to content

Commit 38e1344

Browse files
author
Myles Borins
committed
http_parser: revert d77c3bf
As noted in #5555 the changes to http_parser to use `MakeCallback` have caused a regression that stops Throws from propagating inside of the http client libs. A test and more information can be found at https://gist.github.com/TheAlphaNerd/6615a27684deb682dfe7 This revert is being applied directly to v5.x As such will have no PR-URL. Fix: #5555
1 parent 01c331e commit 38e1344

File tree

3 files changed

+9
-22
lines changed

3 files changed

+9
-22
lines changed

src/async-wrap.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ namespace node {
1717
V(FSREQWRAP) \
1818
V(GETADDRINFOREQWRAP) \
1919
V(GETNAMEINFOREQWRAP) \
20-
V(HTTPPARSER) \
2120
V(JSSTREAM) \
2221
V(PIPEWRAP) \
2322
V(PIPECONNECTWRAP) \

src/node_http_parser.cc

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#include "node_buffer.h"
33
#include "node_http_parser.h"
44

5-
#include "async-wrap.h"
6-
#include "async-wrap-inl.h"
5+
#include "base-object.h"
6+
#include "base-object-inl.h"
77
#include "env.h"
88
#include "env-inl.h"
99
#include "stream_base.h"
@@ -147,10 +147,10 @@ struct StringPtr {
147147
};
148148

149149

150-
class Parser : public AsyncWrap {
150+
class Parser : public BaseObject {
151151
public:
152152
Parser(Environment* env, Local<Object> wrap, enum http_parser_type type)
153-
: AsyncWrap(env, wrap, AsyncWrap::PROVIDER_HTTPPARSER),
153+
: BaseObject(env, wrap),
154154
current_buffer_len_(0),
155155
current_buffer_data_(nullptr) {
156156
Wrap(object(), this);
@@ -164,11 +164,6 @@ class Parser : public AsyncWrap {
164164
}
165165

166166

167-
size_t self_size() const override {
168-
return sizeof(*this);
169-
}
170-
171-
172167
HTTP_CB(on_message_begin) {
173168
num_fields_ = num_values_ = 0;
174169
url_.Reset();
@@ -290,10 +285,8 @@ class Parser : public AsyncWrap {
290285

291286
argv[A_UPGRADE] = Boolean::New(env()->isolate(), parser_.upgrade);
292287

293-
Environment::AsyncCallbackScope callback_scope(env());
294-
295288
Local<Value> head_response =
296-
MakeCallback(cb.As<Function>(), ARRAY_SIZE(argv), argv);
289+
cb.As<Function>()->Call(obj, ARRAY_SIZE(argv), argv);
297290

298291
if (head_response.IsEmpty()) {
299292
got_exception_ = true;
@@ -328,7 +321,7 @@ class Parser : public AsyncWrap {
328321
Integer::NewFromUnsigned(env()->isolate(), length)
329322
};
330323

331-
Local<Value> r = MakeCallback(cb.As<Function>(), ARRAY_SIZE(argv), argv);
324+
Local<Value> r = cb.As<Function>()->Call(obj, ARRAY_SIZE(argv), argv);
332325

333326
if (r.IsEmpty()) {
334327
got_exception_ = true;
@@ -351,9 +344,7 @@ class Parser : public AsyncWrap {
351344
if (!cb->IsFunction())
352345
return 0;
353346

354-
Environment::AsyncCallbackScope callback_scope(env());
355-
356-
Local<Value> r = MakeCallback(cb.As<Function>(), 0, nullptr);
347+
Local<Value> r = cb.As<Function>()->Call(obj, 0, nullptr);
357348

358349
if (r.IsEmpty()) {
359350
got_exception_ = true;
@@ -593,7 +584,7 @@ class Parser : public AsyncWrap {
593584
parser->current_buffer_len_ = nread;
594585
parser->current_buffer_data_ = buf->base;
595586

596-
parser->MakeCallback(cb.As<Function>(), 1, &ret);
587+
cb.As<Function>()->Call(obj, 1, &ret);
597588

598589
parser->current_buffer_len_ = 0;
599590
parser->current_buffer_data_ = nullptr;
@@ -680,7 +671,7 @@ class Parser : public AsyncWrap {
680671
url_.ToString(env())
681672
};
682673

683-
Local<Value> r = MakeCallback(cb.As<Function>(), ARRAY_SIZE(argv), argv);
674+
Local<Value> r = cb.As<Function>()->Call(obj, ARRAY_SIZE(argv), argv);
684675

685676
if (r.IsEmpty())
686677
got_exception_ = true;

test/parallel/test-async-wrap-check-providers.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const tls = require('tls');
1111
const zlib = require('zlib');
1212
const ChildProcess = require('child_process').ChildProcess;
1313
const StreamWrap = require('_stream_wrap').StreamWrap;
14-
const HTTPParser = process.binding('http_parser').HTTPParser;
1514
const async_wrap = process.binding('async_wrap');
1615
const pkeys = Object.keys(async_wrap.Providers);
1716

@@ -107,8 +106,6 @@ zlib.createGzip();
107106

108107
new ChildProcess();
109108

110-
new HTTPParser(HTTPParser.REQUEST);
111-
112109
process.on('exit', function() {
113110
if (keyList.length !== 0) {
114111
process._rawDebug('Not all keys have been used:');

0 commit comments

Comments
 (0)