|
| 1 | +Import-Module (Join-Path $PSScriptRoot "..\utils.psm1") |
| 2 | + |
| 3 | +function Patch { |
| 4 | + param([string]$Content) |
| 5 | + |
| 6 | + $Content = Edit-FunctionBody -Content $Content ` |
| 7 | + -FunctionName "void SharedFunctionInfo::SharedFunctionInfoPrint" ` |
| 8 | + -Converter { |
| 9 | + param($Body) |
| 10 | + $Body = Set-CommentLine -Content $Body -Pattern "\s*PrintSourceCode\(os\);" |
| 11 | + $Body += "`n" |
| 12 | + $Body += @" |
| 13 | + os << "\nStart BytecodeArray\n"; |
| 14 | + // TODO: isolate may be invalid |
| 15 | + this->GetActiveBytecodeArray(isolate)->Disassemble(os); |
| 16 | + os << "\nEnd BytecodeArray\n"; |
| 17 | + os << std::flush; |
| 18 | +"@ |
| 19 | + return $Body |
| 20 | + } |
| 21 | + |
| 22 | + $Content = Edit-FunctionBody -Content $Content ` |
| 23 | + -FunctionName "void HeapObject::HeapObjectShortPrint" ` |
| 24 | + -Converter { |
| 25 | + param($Body) |
| 26 | + $Body = Add-LineBelow -Content $Body ` |
| 27 | + -Patterns @('cage_base =') ` |
| 28 | + -Insert @" |
| 29 | + Isolate* isolate = nullptr; |
| 30 | + if (!GetIsolateFromHeapObject(*this, &isolate) || isolate == nullptr) { |
| 31 | + os << "[!!! Corrupted HeapObject (cannot get Isolate) at " |
| 32 | + << reinterpret_cast<void*>(this->ptr()) << " !!!]"; |
| 33 | + return; |
| 34 | + } |
| 35 | + ReadOnlyRoots roots(isolate); |
| 36 | + Tagged<Map> map_of_this_object = this->map(cage_base); |
| 37 | + if (map_of_this_object.ptr() == kNullAddress) { |
| 38 | + os << "[!!! Corrupted HeapObject (null map pointer) at " |
| 39 | + << reinterpret_cast<void*>(this->ptr()) << " !!!]"; |
| 40 | + return; |
| 41 | + } |
| 42 | + if (map_of_this_object->map(cage_base) != roots.meta_map()) { |
| 43 | + os << "[!!! Corrupted HeapObject (invalid map) at " |
| 44 | + << reinterpret_cast<void*>(this->ptr()) << " !!!]"; |
| 45 | + return; |
| 46 | + } |
| 47 | +"@ |
| 48 | + $Body = Add-LineBefore -Content $Body ` |
| 49 | + -Pattern '\s*switch \(map\(cage_base\)->instance_type\(\)\) {' ` |
| 50 | + -Insert @" |
| 51 | + if (map(cage_base)->instance_type() == ASM_WASM_DATA_TYPE) { |
| 52 | + os << "<ArrayBoilerplateDescription> "; |
| 53 | + Cast<ArrayBoilerplateDescription>(*this) |
| 54 | + ->constant_elements() |
| 55 | + .GetHeapObject() |
| 56 | + ->HeapObjectShortPrint(os); |
| 57 | + return; |
| 58 | + } |
| 59 | +"@ |
| 60 | + $Body = Add-LineBelow -Content $Body ` |
| 61 | + -Patterns @('case FIXED_ARRAY_TYPE:', ';') ` |
| 62 | + -Insert @" |
| 63 | + os << "\nStart FixedArray\n"; |
| 64 | + Cast<FixedArray>(*this)->FixedArrayPrint(os); |
| 65 | + os << "\nEnd FixedArray\n"; |
| 66 | +"@ |
| 67 | + $Body = Add-LineBelow -Content $Body ` |
| 68 | + -Patterns @('case OBJECT_BOILERPLATE_DESCRIPTION_TYPE:', ';') ` |
| 69 | + -Insert @" |
| 70 | + os << "\nStart ObjectBoilerplateDescription\n"; |
| 71 | + Cast<ObjectBoilerplateDescription>(*this) |
| 72 | + ->ObjectBoilerplateDescriptionPrint(os); |
| 73 | + os << "\nEnd ObjectBoilerplateDescription\n"; |
| 74 | +"@ |
| 75 | + $Body = Add-LineBelow -Content $Body ` |
| 76 | + -Patterns @('case FIXED_DOUBLE_ARRAY_TYPE:', ';') ` |
| 77 | + -Insert @" |
| 78 | + os << "\nStart FixedDoubleArray\n"; |
| 79 | + Cast<FixedDoubleArray>(*this)->FixedDoubleArrayPrint(os); |
| 80 | + os << "\nEnd FixedDoubleArray\n"; |
| 81 | +"@ |
| 82 | + $Body = Add-LineBelow -Content $Body ` |
| 83 | + -Patterns @('case SHARED_FUNCTION_INFO_TYPE:', 'else', '}') ` |
| 84 | + -Insert @" |
| 85 | + os << "\nStart SharedFunctionInfo\n"; |
| 86 | + shared->SharedFunctionInfoPrint(os); |
| 87 | + os << "\nEnd SharedFunctionInfo\n"; |
| 88 | +"@ |
| 89 | + return $Body |
| 90 | + } |
| 91 | + |
| 92 | + return $Content |
| 93 | +} |
0 commit comments