sebastienros / jint

Javascript Interpreter for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

URL API

robertmuehsig opened this issue · comments

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.

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 .