16
16
namespace fibjs {
17
17
18
18
class JSHandler : public Handler_base {
19
+
20
+ public:
21
+ JSHandler (v8::Local<v8::Value> proc, bool async = false );
22
+
19
23
FIBER_FREE ();
20
24
21
25
public:
@@ -31,10 +35,10 @@ class JSHandler : public Handler_base {
31
35
AsyncEvent* ac);
32
36
33
37
public:
34
- static result_t New (v8::Local<v8::Value> hdlr,
35
- obj_ptr<Handler_base>& retVal)
38
+ static result_t New (v8::Local<v8::Value> hdlr, obj_ptr<Handler_base>& retVal)
36
39
{
37
- if (hdlr->IsString () || hdlr->IsStringObject () || hdlr->IsNumberObject () || hdlr->IsRegExp () || (!hdlr->IsFunction () && !hdlr->IsObject ()))
40
+ if (hdlr->IsString () || hdlr->IsStringObject () || hdlr->IsNumberObject () || hdlr->IsRegExp ()
41
+ || (!hdlr->IsFunction () && !hdlr->IsObject ()))
38
42
return CHECK_ERROR (CALL_E_BADVARTYPE);
39
43
40
44
retVal = Handler_base::getInstance (hdlr);
@@ -53,9 +57,8 @@ class JSHandler : public Handler_base {
53
57
return 0 ;
54
58
}
55
59
60
+ v8::Local<v8::Object> o = v8::Local<v8::Object>::Cast (hdlr);
56
61
if (!hdlr->IsFunction ()) {
57
- v8::Local<v8::Object> o = v8::Local<v8::Object>::Cast (hdlr);
58
-
59
62
obj_ptr<Routing_base> r = new Routing ();
60
63
result_t hr = r->append (o);
61
64
if (hr < 0 )
@@ -65,16 +68,25 @@ class JSHandler : public Handler_base {
65
68
return 0 ;
66
69
}
67
70
68
- obj_ptr<JSHandler> r = new JSHandler ();
69
- r->SetPrivate (" handler" , hdlr);
71
+ Isolate* isolate = Isolate::current ();
72
+ v8::Local<v8::Value> _async = o->GetPrivate (o->CreationContext (),
73
+ v8::Private::ForApi (isolate->m_isolate , isolate->NewFromUtf8 (" _async" )))
74
+ .ToLocalChecked ();
75
+
76
+ if (!IsEmpty (_async))
77
+ retVal = new JSHandler (_async, true );
78
+ else
79
+ retVal = new JSHandler (hdlr);
70
80
71
- retVal = r;
72
81
return 0 ;
73
82
}
74
83
75
84
public:
76
85
static result_t js_invoke (Handler_base* hdlr, object_base* v,
77
86
obj_ptr<Handler_base>& retVal, AsyncEvent* ac);
87
+
88
+ private:
89
+ bool m_async;
78
90
};
79
91
80
92
} /* namespace fibjs */
0 commit comments