mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-09-08 17:51:20 +02:00
Fix invocation error
This commit is contained in:
parent
c904e591b0
commit
bdf2c0397e
@ -102,15 +102,23 @@ export function createStirlingFile(file: File, id?: FileId): StirlingFile {
|
|||||||
const fileId = id || createFileId();
|
const fileId = id || createFileId();
|
||||||
const quickKey = createQuickKey(file);
|
const quickKey = createQuickKey(file);
|
||||||
|
|
||||||
// Create a new object that inherits from the File instance
|
// Use Object.defineProperty to add properties while preserving the original File object
|
||||||
// This preserves all File methods and properties while avoiding binding issues
|
// This maintains proper method binding and avoids "Illegal invocation" errors
|
||||||
const stirlingFile = Object.assign(
|
Object.defineProperty(file, 'fileId', {
|
||||||
Object.create(Object.getPrototypeOf(file)), // Proper prototype chain
|
value: fileId,
|
||||||
file, // Copy all properties (enumerable and non-enumerable)
|
writable: false,
|
||||||
{ fileId, quickKey } // Add our custom properties
|
enumerable: true,
|
||||||
) as StirlingFile;
|
configurable: false
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(file, 'quickKey', {
|
||||||
|
value: quickKey,
|
||||||
|
writable: false,
|
||||||
|
enumerable: true,
|
||||||
|
configurable: false
|
||||||
|
});
|
||||||
|
|
||||||
return stirlingFile;
|
return file as StirlingFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract FileIds from StirlingFile array
|
// Extract FileIds from StirlingFile array
|
||||||
|
Loading…
Reference in New Issue
Block a user