sebastienros / jint

Javascript Interpreter for .NET
BSD 2-Clause "Simplified" License
4.02k stars 556 forks source link

URL API #1877

Closed robertmuehsig closed 2 months ago

robertmuehsig commented 2 months ago

Is your feature request related to a problem? Please describe.

I discovered the URL API which helps to create "valid" URL or parse them. Unfortunately it seems Jint is not able to execute such code:

var engine = new Engine()
    .SetValue("log", new Action<object>(Console.WriteLine));

engine.Execute(@"
    function hello() { 

const myUrlWithParams = new URL(""https://www.example.dev/"");
myUrlWithParams.searchParams.append(""city"", ""Rome"");myUrlWithParams.searchParams.append(""price"", ""200"");
log(myUrlWithParams.href);// output: https://www.example.dev/?city=Rome&price=200

        log('Hello World');
    };

    hello();
");

Error: JavaScriptErrorWrapperException: URL is not defined

I'm not sure if this is a "bug" or a "feature request" and I'm not even sure if such an API should be part of Jint or not, but this function would be really handy.

lahma commented 2 months ago

This is not core functionality for Jint as there's a lot of Web API features and nobody to create or maintain them. You could probably try out some polyfill like https://github.com/lifaon74/url-polyfill .