Fix invocation error

This commit is contained in:
Reece Browne 2025-09-04 10:43:15 +01:00
parent c904e591b0
commit bdf2c0397e

View File

@ -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