Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Correctly detect Node environment #1262

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

felixrieseberg
Copy link
Contributor

Right now, v86 prefers XMLHttpRequest when available. I'm patching this in my Electron use case to prefer fs for performance reasons.

With this change, v86 prefers XMLHttpRequest when available and process.versions.node is undefined. If desired, I'm also happy to write a simple try/catch function that returns a boolean if require('fs') works.

@copy
Copy link
Owner

copy commented Feb 23, 2025

With this change, v86 prefers XMLHttpRequest when available and process.versions.node is undefined. If desired, I'm also happy to write a simple try/catch function that returns a boolean if require('fs') works.

I think it would be nice if we could move all three occurrences into src/lib.js and write this only once, e.g.:

let fs;
if(typeof require !== "undefined")
{
    try {
        fs = require("fs");
    }
    catch(e) {}
}

if(fs)
{
    v86util.determine_size = ... // using fs
    v86util.load_file = ...
}
else
{
    v86util.determine_size = ... // using xhr
    v86util.load_file = ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants