-
Notifications
You must be signed in to change notification settings - Fork 17.1k
Scope issues with eval() #8854
Copy link
Copy link
Closed
Labels
blocked/need-info ❌Cannot proceed without more informationCannot proceed without more informationbug 🪲
Description
- Electron version: 1.6.2
- Operating system: Windows 10 64-bit
Expected behavior
eval() should run in the current scope and be able to access global variables. The following script, which is executed on the main process (global scope), should produce no error (in fact, it does work properly in Electron v1.4.15).
eval(
"const app = electron.app;\n"
+ "const BrowserWindow = electron.BrowserWindow;\n"
+ "app.on('ready', function() {\n"
+ " mainWindow = new BrowserWindow({ ... });\n"
+ "});"
);
Actual behavior
Error occurs on the "new BrowserWindow" part saying BrowserWindow is not defined. The defined global variable BrowserWindow is not accessible inside the function.
As a workaround, I have to enclose the script inside an anonymous self-invoking function so that a local scope is created to avoid the problem.
eval (
"(function () {\n"
......
+ "})();"
);
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
blocked/need-info ❌Cannot proceed without more informationCannot proceed without more informationbug 🪲