-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmp_fix_destroy_style.ps1
More file actions
109 lines (98 loc) · 5.89 KB
/
tmp_fix_destroy_style.ps1
File metadata and controls
109 lines (98 loc) · 5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
$path = 'd:\Z8\Z8-app\src\module\node\stream\stream.cpp'
$raw = Get-Content -Raw -Path $path
# 1. Implementation of streamDestroy with correct style
$newRD = 'void Stream::streamDestroy(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* p_isolate = args.GetIsolate();
v8::Local<v8::Context> context = p_isolate->GetCurrentContext();
v8::Local<v8::Object> self = args.This();
v8::Local<v8::Value> internal_ext = self->GetInternalField(0);
if (internal_ext.IsEmpty() || !internal_ext->IsExternal()) return;
StreamInternal* p_internal = static_cast<StreamInternal*>(internal_ext.As<v8::External>()->Value());
if (p_internal->m_destroyed) {
args.GetReturnValue().Set(self);
return;
}
p_internal->m_destroyed = true;
v8::Local<v8::Value> error = args.Length() > 0 ? args[0] : v8::Undefined(p_isolate).As<v8::Value>();
if (!error->IsUndefined() && !error->IsNull()) {
v8::Local<v8::Value> emit_val;
if (self->Get(context, v8::String::NewFromUtf8Literal(p_isolate, "emit")).ToLocal(&emit_val) && emit_val->IsFunction()) {
v8::Local<v8::Value> argv[] = { v8::String::NewFromUtf8Literal(p_isolate, "error"), error };
(void)emit_val.As<v8::Function>()->Call(context, self, 2, argv);
}
}
v8::Local<v8::Value> destroy_val;
if (self->Get(context, v8::String::NewFromUtf8Literal(p_isolate, "_destroy")).ToLocal(&destroy_val) && destroy_val->IsFunction()) {
v8::Local<v8::Function> cb = v8::Function::New(context, [](const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* p_isolate_inner = args.GetIsolate();
v8::Local<v8::Context> context_inner = p_isolate_inner->GetCurrentContext();
v8::Local<v8::Object> self_inner = args.This();
StreamInternal* p_internal_inner = static_cast<StreamInternal*>(self_inner->GetInternalField(0).As<v8::External>()->Value());
p_internal_inner->m_closed = true;
v8::Local<v8::Value> emit_val_inner;
if (self_inner->Get(context_inner, v8::String::NewFromUtf8Literal(p_isolate_inner, "emit")).ToLocal(&emit_val_inner) && emit_val_inner->IsFunction()) {
v8::Local<v8::Value> argv[] = { v8::String::NewFromUtf8Literal(p_isolate_inner, "close") };
(void)emit_val_inner.As<v8::Function>()->Call(context_inner, self_inner, 1, argv);
}
}).ToLocalChecked();
v8::Local<v8::Value> argv[] = { error, cb };
(void)destroy_val.As<v8::Function>()->Call(context, self, 2, argv);
} else {
p_internal->m_closed = true;
v8::Local<v8::Value> emit_val;
if (self->Get(context, v8::String::NewFromUtf8Literal(p_isolate, "emit")).ToLocal(&emit_val) && emit_val->IsFunction()) {
v8::Local<v8::Value> argv[] = { v8::String::NewFromUtf8Literal(p_isolate, "close") };
(void)emit_val.As<v8::Function>()->Call(context, self, 1, argv);
}
}
args.GetReturnValue().Set(self);
}'
# We need to replace what is CURRENTLY in the file.
# Since we already ran the previous patch once, the file has the 'bad' streamDestroy.
$currentBAD = 'void Stream::streamDestroy(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* p_isolate = args.GetIsolate();
v8::Local<v8::Context> context = p_isolate->GetCurrentContext();
v8::Local<v8::Object> self = args.This();
v8::Local<v8::External> ext = self->GetInternalField(0).As<v8::External>();
if (ext.IsEmpty() || !ext->IsExternal()) return;
StreamInternal* p_internal = static_cast<StreamInternal*>(ext->Value());
if (p_internal->m_destroyed) {
args.GetReturnValue().Set(self);
return;
}
p_internal->m_destroyed = true;
v8::Local<v8::Value> error = args.Length() > 0 ? args[0] : v8::Undefined(p_isolate).As<v8::Value>();
if (!error->IsUndefined() && !error->IsNull()) {
v8::Local<v8::Value> emit_val;
if (self->Get(context, v8::String::NewFromUtf8Literal(p_isolate, "emit")).ToLocal(&emit_val) && emit_val->IsFunction()) {
v8::Local<v8::Value> argv[] = { v8::String::NewFromUtf8Literal(p_isolate, "error"), error };
(void)emit_val.As<v8::Function>()->Call(context, self, 2, argv);
}
}
v8::Local<v8::Value> destroy_val;
if (self->Get(context, v8::String::NewFromUtf8Literal(p_isolate, "_destroy")).ToLocal(&destroy_val) && destroy_val->IsFunction()) {
v8::Local<v8::Function> cb = v8::Function::New(context, [](const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* p_isolate_inner = args.GetIsolate();
v8::Local<v8::Context> context_inner = p_isolate_inner->GetCurrentContext();
v8::Local<v8::Object> s = args.This();
StreamInternal* pi = static_cast<StreamInternal*>(s->GetInternalField(0).As<v8::External>()->Value());
pi->m_closed = true;
v8::Local<v8::Value> emit_val_inner;
if (s->Get(context_inner, v8::String::NewFromUtf8Literal(p_isolate_inner, "emit")).ToLocal(&emit_val_inner) && emit_val_inner->IsFunction()) {
v8::Local<v8::Value> argv[] = { v8::String::NewFromUtf8Literal(p_isolate_inner, "close") };
(void)emit_val_inner.As<v8::Function>()->Call(context_inner, s, 1, argv);
}
}).ToLocalChecked();
v8::Local<v8::Value> argv[] = { error, cb };
(void)destroy_val.As<v8::Function>()->Call(context, self, 2, argv);
} else {
p_internal->m_closed = true;
v8::Local<v8::Value> emit_val;
if (self->Get(context, v8::String::NewFromUtf8Literal(p_isolate, "emit")).ToLocal(&emit_val) && emit_val->IsFunction()) {
v8::Local<v8::Value> argv[] = { v8::String::NewFromUtf8Literal(p_isolate, "close") };
(void)emit_val.As<v8::Function>()->Call(context, self, 1, argv);
}
}
args.GetReturnValue().Set(self);
}'
$raw.Replace($currentBAD, $newRD) | Set-Content -Path $path