|
4 | 4 |
|
5 | 5 | using v8::Context;
|
6 | 6 | using v8::External;
|
| 7 | +using v8::Function; |
7 | 8 | using v8::FunctionCallbackInfo;
|
8 | 9 | using v8::FunctionTemplate;
|
9 | 10 | using v8::Local;
|
@@ -77,30 +78,35 @@ void StreamPipe::Unpipe() {
|
77 | 78 | Context::Scope context_scope(env->context());
|
78 | 79 | Local<Object> object = pipe->object();
|
79 | 80 |
|
80 |
| - if (object->Has(env->context(), env->onunpipe_string()).FromJust()) { |
81 |
| - pipe->MakeCallback(env->onunpipe_string(), 0, nullptr).ToLocalChecked(); |
| 81 | + Local<Value> onunpipe; |
| 82 | + if (!object->Get(env->context(), env->onunpipe_string()).ToLocal(&onunpipe)) |
| 83 | + return; |
| 84 | + if (onunpipe->IsFunction() && |
| 85 | + pipe->MakeCallback(onunpipe.As<Function>(), 0, nullptr).IsEmpty()) { |
| 86 | + return; |
82 | 87 | }
|
83 | 88 |
|
84 | 89 | // Set all the links established in the constructor to `null`.
|
85 | 90 | Local<Value> null = Null(env->isolate());
|
86 | 91 |
|
87 | 92 | Local<Value> source_v;
|
88 | 93 | Local<Value> sink_v;
|
89 |
| - source_v = object->Get(env->context(), env->source_string()) |
90 |
| - .ToLocalChecked(); |
91 |
| - sink_v = object->Get(env->context(), env->sink_string()) |
92 |
| - .ToLocalChecked(); |
93 |
| - CHECK(source_v->IsObject()); |
94 |
| - CHECK(sink_v->IsObject()); |
95 |
| - |
96 |
| - object->Set(env->context(), env->source_string(), null).FromJust(); |
97 |
| - object->Set(env->context(), env->sink_string(), null).FromJust(); |
98 |
| - source_v.As<Object>()->Set(env->context(), |
99 |
| - env->pipe_target_string(), |
100 |
| - null).FromJust(); |
101 |
| - sink_v.As<Object>()->Set(env->context(), |
102 |
| - env->pipe_source_string(), |
103 |
| - null).FromJust(); |
| 94 | + if (!object->Get(env->context(), env->source_string()).ToLocal(&source_v) || |
| 95 | + !object->Get(env->context(), env->sink_string()).ToLocal(&sink_v) || |
| 96 | + !source_v->IsObject() || !sink_v->IsObject()) { |
| 97 | + return; |
| 98 | + } |
| 99 | + |
| 100 | + if (object->Set(env->context(), env->source_string(), null).IsNothing() || |
| 101 | + object->Set(env->context(), env->sink_string(), null).IsNothing() || |
| 102 | + source_v.As<Object>() |
| 103 | + ->Set(env->context(), env->pipe_target_string(), null) |
| 104 | + .IsNothing() || |
| 105 | + sink_v.As<Object>() |
| 106 | + ->Set(env->context(), env->pipe_source_string(), null) |
| 107 | + .IsNothing()) { |
| 108 | + return; |
| 109 | + } |
104 | 110 | }, static_cast<void*>(this), object());
|
105 | 111 | }
|
106 | 112 |
|
|
0 commit comments