diff --git a/src/main/java/delight/nashornsandbox/internal/NashornSandboxImpl.java b/src/main/java/delight/nashornsandbox/internal/NashornSandboxImpl.java index 634aa16..5456e19 100644 --- a/src/main/java/delight/nashornsandbox/internal/NashornSandboxImpl.java +++ b/src/main/java/delight/nashornsandbox/internal/NashornSandboxImpl.java @@ -112,33 +112,6 @@ public NashornSandboxImpl(ScriptEngine engine, String... params) { this.allow(InterruptTest.class); this.engineAsserted = new AtomicBoolean(false); - // for (String param : params) { - // if (param.equals("--language=es6")) { - // this.allow(java.util.Timer.class); - // try (final BufferedReader reader = new BufferedReader(new InputStreamReader( - // new BufferedInputStream(JsSanitizer.class.getResourceAsStream("resources/es6/nashorn-ext-for-es6.js")), - // StandardCharsets.UTF_8))) { - // final StringBuilder sb = new StringBuilder(); - // String line; - // while ((line = reader.readLine()) != null) { - // sb.append(line).append('\n'); - // } - // final String script = sb.toString(); - // try { - // this.allowGlobalsObjects(true); - // this.allowLoadFunctions(true); - // this.allowGlobalsObjects(true); - // this.scriptEngine.eval(script+"\nArray.from(1,2,3);"); - // } catch (ScriptCPUAbuseException e) { - // throw new RuntimeException("CPU usage exceeded from loading Nashorn ES6 extension.."); - // } catch (ScriptException e) { - // throw new RuntimeException("Script error while loading Nashorn ES6 extension.", e); - // } - // } catch (final IOException e) { - // throw new RuntimeException("Cannot find file: resources/es6/nashorn-ext-for-es6.js", e); - // } - // } - // } } private SandboxClassFilter createSandboxClassFilter() { diff --git a/src/main/java/delight/nashornsandbox/internal/resources/es6/LICENSE b/src/main/java/delight/nashornsandbox/internal/resources/es6/LICENSE deleted file mode 100644 index f48c212..0000000 --- a/src/main/java/delight/nashornsandbox/internal/resources/es6/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2023 efw group - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/src/main/java/delight/nashornsandbox/internal/resources/es6/nashorn-ext-for-es6.js b/src/main/java/delight/nashornsandbox/internal/resources/es6/nashorn-ext-for-es6.js deleted file mode 100644 index 1b51a55..0000000 --- a/src/main/java/delight/nashornsandbox/internal/resources/es6/nashorn-ext-for-es6.js +++ /dev/null @@ -1,1032 +0,0 @@ -/**************************** -MIT License - -Copyright (c) 2023 efwGrp - -https://github.com/efwGrp/nashorn-ext-for-es6 -****************************/ -"use strict"; -/////////////////////////////////////////////////////////////////////////////// -/** -The Math.log10() static method returns the base 10 logarithm of a number. -ECMAScript 2015 -*/ -if (Math.log10==null){ - Math.log10=function(x){ - return Math.log(x) * Math.LOG10E; - } - Object.defineProperty(Math, "log10", {enumerable: false}); -} -/** -The Math.log2() static method returns the base 2 logarithm of a number. -ECMAScript 2015 -*/ -if (Math.log2==null){ - Math.log2=function(x){ - return Math.log(x) * Math.LOG2E; - } - Object.defineProperty(Math, "log2", {enumerable: false}); -} -/** -The Math.log1p() static method returns the natural logarithm (base e) of 1 + x, where x is the argument. -ECMAScript 2015 -*/ -if (Math.log1p==null){ - Math.log1p=function(x){ - x = Number(x); - if (x < -1 || x !== x) return NaN; - if (x === 0 || x === Infinity) return x; - var nearX = x + 1 - 1; - return nearX === 0 ? x : x * (Math.log(x + 1) / nearX); - } - Object.defineProperty(Math, "log1p", {enumerable: false}); -} -/** -Math.expm1The Math.expm1() static method returns e raised to the power of a number, subtracted by 1. -ECMAScript 2015 -*/ -if (Math.expm1==null){ - Math.expm1=function(x){ - return Math.exp(x) - 1; - } - Object.defineProperty(Math, "expm1", {enumerable: false}); -} -/** -The Math.sinh() static method returns the hyperbolic sine of a number. -ECMAScript 2015 -*/ -if (Math.sinh==null){ - Math.sinh=function(x){ - return (Math.exp(x) - Math.exp(-x)) / 2; - } - Object.defineProperty(Math, "sinh", {enumerable: false}); -} -/** -The Math.cosh() static method returns the hyperbolic cosine of a number. -ECMAScript 2015 -*/ -if (Math.cosh==null){ - Math.cosh=function(x){ - return (Math.exp(x) + Math.exp(-x)) / 2; - } - Object.defineProperty(Math, "cosh", {enumerable: false}); -} -/** -The Math.tanh() static method returns the hyperbolic tangent of a number. -ECMAScript 2015 -*/ -if (Math.tanh==null){ - Math.tanh=function(x){ - var a = Math.exp(+x),b = Math.exp(-x); - return a == Infinity ? 1 : b == Infinity ? -1 : (a - b) / (a + b); - } - Object.defineProperty(Math, "tanh", {enumerable: false}); -} -/** -The Math.asinh() static method returns the inverse hyperbolic sine of a number. -ECMAScript 2015 -*/ -if (Math.asinh==null){ - Math.asinh=function(x){ - var absX = Math.abs(x),w; - if (absX < 3.725290298461914e-9) - // |x| < 2^-28 - return x; - if (absX > 268435456) - // |x| > 2^28 - w = Math.log(absX) + Math.LN2; - else if (absX > 2) - // 2^28 >= |x| > 2 - w = Math.log(2 * absX + 1 / (Math.sqrt(x * x + 1) + absX)); - else - var t = x * x, - w = Math.log1p(absX + t / (1 + Math.sqrt(1 + t))); - - return x > 0 ? w : -w; - } - Object.defineProperty(Math, "asinh", {enumerable: false}); -} -/** -The Math.acosh() static method returns the inverse hyperbolic cosine of a number. -ECMAScript 2015 -*/ -if (Math.acosh==null){ - Math.acosh=function(x){ - return Math.log(x + Math.sqrt(x * x - 1)); - } - Object.defineProperty(Math, "acosh", {enumerable: false}); -} -/** -The Math.atanh() static method returns the inverse hyperbolic tangent of a number. -ECMAScript 2015 -*/ -if (Math.atanh==null){ - Math.atanh=function(x){ - return Math.log((1 + x) / (1 - x)) / 2; - } - Object.defineProperty(Math, "atanh", {enumerable: false}); -} -/** -The Math.hypot() static method returns the square root of the sum of squares of its arguments. -ECMAScript 2015 -*/ -if (Math.hypot==null){ - Math.hypot=function(){ - var y = 0,i = arguments.length,containsInfinity = false; - while (i--) { - var arg = arguments[i]; - if (arg === Infinity || arg === -Infinity) containsInfinity = true; - y += arg * arg; - } - return containsInfinity ? Infinity : Math.sqrt(y); - } - Object.defineProperty(Math, "hypot", {enumerable: false}); -} -/** -The Math.trunc() static method returns the integer part of a number by removing any fractional digits. -ECMAScript 2015 -*/ -if (Math.trunc==null){ - Math.trunc=function(x){ - return x < 0 ? Math.ceil(x) : Math.floor(x); - } - Object.defineProperty(Math, "trunc", {enumerable: false}); -} -/** -The Math.sign() static method returns 1 or -1, indicating the sign of the number passed as argument. -ECMAScript 2015 -*/ -if (Math.sign==null){ - Math.sign=function(x){ - return (x > 0) - (x < 0) || +x; - } - Object.defineProperty(Math, "sign", {enumerable: false}); -} -/** -The Math.cbrt() static method returns the cube root of a number. -ECMAScript 2015 -*/ -if (Math.cbrt==null){ - Math.cbrt=function(x){ - return x < 0 ? -Math.pow(-x, 1 / 3) : Math.pow(x, 1 / 3); - } - Object.defineProperty(Math, "cbrt", {enumerable: false}); -} -/** -The Math.imul() static method returns the result of the C-like 32-bit multiplication of the two parameters. -ECMAScript 2015 -*/ -if (Math.imul==null){ - Math.imul=function(a,b){ - var aHi = (a >>> 16) & 0xffff; - var aLo = a & 0xffff; - var bHi = (b >>> 16) & 0xffff; - var bLo = b & 0xffff; - // the shift by 0 fixes the sign on the high part - // the final |0 converts the unsigned value into a signed value - return (aLo * bLo + (((aHi * bLo + aLo * bHi) << 16) >>> 0)) | 0; - } - Object.defineProperty(Math, "imul", {enumerable: false}); -} -/** -The Math.fround() static method returns the nearest 32-bit single precision float representation of a number. -ECMAScript 2015 -*/ -if (Math.fround==null){ - Math.fround=function(x){ - var array=new Float32Array(1); - return (array[0] = x), array[0]; - } - Object.defineProperty(Math, "fround", {enumerable: false}); -} -/** -The Math.clz32() static method returns the number of leading zero bits in the 32-bit binary representation of a number. -ECMAScript 2015 -*/ -if (Math.clz32==null){ - Math.clz32=function(x){ - // Let n be ToUint32(x). - // Let p be the number of leading zero bits in - // the 32-bit binary representation of n. - // Return p. - var asUint = x >>> 0; - if (asUint === 0) { - return 32; - } - return (31 - ((Math.log(asUint) / Math.LN2) | 0)) | 0; // the "| 0" acts like math.floor - } - Object.defineProperty(Math, "clz32", {enumerable: false}); -} -/////////////////////////////////////////////////////////////////////////////// -/** -The Number.EPSILON static data property represents the difference between 1 and the smallest floating point number greater than 1. -ECMAScript 2015 -*/ -if (Number.EPSILON==null){ - Number.EPSILON=2.2204460492503130808472633361816E-16; - Object.defineProperty(Number, "EPSILON", {enumerable: false}); -} -/** -The Number.isFinite() static method determines whether the passed value is a finite number. -ECMAScript 2015 -*/ -if (Number.isFinite==null){ - Number.isFinite=function(x){ - return typeof x === "number" && isFinite(x); - } - Object.defineProperty(Number, "isFinite", {enumerable: false}); -} -/** -The Number.isInteger() static method determines whether the passed value is an integer. -ECMAScript 2015 -*/ -if (Number.isInteger==null){ - Number.isInteger=function(x){ - if (typeof x !== "number") return false; - return x % 1 === 0; - } - Object.defineProperty(Number, "isInteger", {enumerable: false}); -} -/** -The Number.isNaN() static method determines whether the passed value is the number value NaN, and returns false if the input is not of the Number type. -ECMAScript 2015 -*/ -if (Number.isNaN==null){ - Number.isNaN=function(x){ - return x !== x; - } - Object.defineProperty(Number, "isNaN", {enumerable: false}); -} -/** -The Number.parseFloat() static method parses an argument and returns a floating point number. -ECMAScript 2015 -*/ -if (Number.parseFloat==null){ - Number.parseFloat=function(string){ - return parseFloat(string); - } - Object.defineProperty(Number, "parseFloat", {enumerable: false}); -} -/** -The Number.parseInt() static method parses a string argument and returns an integer of the specified radix or base. -ECMAScript 2015 -*/ -if (Number.parseInt==null){ - Number.parseInt=function(string,radix){ - return parseInt(string,radix); - } - Object.defineProperty(Number, "parseInt", {enumerable: false}); -} -/////////////////////////////////////////////////////////////////////////////// -/** -The codePointAt() method of String values returns a non-negative integer that is the Unicode code point value of the character starting at the given index. -ECMAScript 2015 -*/ -if (String.prototype.codePointAt==null) { - String.prototype.codePointAt = function(position) { - var str = String(this); - var length = str.length; - var size = 0; - var index = 0; - var count = 0; - for (var index = 0; index < length; index += size) { - var high = str.charCodeAt(index); - var low = str.charCodeAt(index + 1); - if ((0xD800 <= high && high <= 0xDBFF) && - (0xDC00 <= low && low <= 0xDFFF) - ) { - if (count == position) { - return (high - 0xD800) * 0x400 + low - 0xDC00 + 0x10000; - } - size = 2; - } else { - if (count == position) { - return high; - } - size = 1; - } - ++count; - } - return undefined; - }; - Object.defineProperty(String.prototype, "codePointAt", {enumerable: false}); -} -/** -The String.fromCodePoint() static method returns a string created from the specified sequence of code points. -ECMAScript 2015 -*/ -if (String.fromCodePoint==null) { - String.fromCodePoint = function fromCodePoint() { - var chars = [], point, offset, i; - var length = arguments.length; - for (i = 0; i < length; ++i) { - point = arguments[i]; - if (point < 0x10000) { - chars.push(point); - } else { - offset = point - 0x10000; - chars.push(0xD800 + (offset >> 10)); - chars.push(0xDC00 + (offset & 0x3FF)); - } - } - return String.fromCharCode.apply(null, chars); - }; - Object.defineProperty(String, "fromCodePoint", {enumerable: false}); -} -/** -The includes() method of String values performs a case-sensitive search to determine whether a given string may be found within this string, returning true or false as appropriate. -ECMAScript 2015 -*/ -if (String.prototype.includes==null){ - String.prototype.includes=function(searchString, position){ - if (position==null)position=0; - if (this.indexOf(searchString,position)>-1){ - return true; - }else{ - return false; - } - } - Object.defineProperty(String.prototype, "includes", {enumerable: false}); -} -/** -The repeat() method of String values constructs and returns a new string which contains the specified number of copies of this string, concatenated together. -ECMAScript 2015 -*/ -if (String.prototype.repeat==null){ - String.prototype.repeat=function(count){ - var ret=""; - for(var i=0;i 0) { - if (from in array) { - array[to] = array[from]; - } else { - delete array[to]; - } - from = from + direction; - to = to + direction; - count--; - } - - return array; - } - Object.defineProperty(Array.prototype, "copyWithin", {enumerable: false}); -} -/** -The includes() method of Array instances determines whether an array includes a certain value among its entries, returning true or false as appropriate. -ECMAScript 2016 -*/ -if (Array.prototype.includes==null){ - Array.prototype.includes=function(searchElement, fromIndex){ - if (fromIndex==null)fromIndex=0; - if (this.indexOf(searchElement)>-1){ - return true; - }else{ - return false; - } - } - Object.defineProperty(Array.prototype, "includes", {enumerable: false}); -} -/** -The flatMap() method of Array instances returns a new array formed by applying a given callback function to each element of the array, and then flattening the result by one level. -ECMAScript 2019 -*/ -if (Array.prototype.flatMap==null){ - Array.prototype.flatMap=function(lambda){ - return [].concat.apply([],this.map(lambda)); - } - Object.defineProperty(Array.prototype, "flatMap", {enumerable: false}); -} -/////////////////////////////////////////////////////////////////////////////// -/** -The Object.assign() static method copies all enumerable own properties from one or more source objects to a target object. It returns the modified target object. -ECMAScript 2015 - */ -if (Object.assign==null){ - Object.assign=function(dest, src/*, …srcn*/) { - for (var i=1; i0?t=t.concat(e.flat(r-1)):t.push(e);return t},Object.defineProperty(Array.prototype,\"flat\",{enumerable:!1});"); - }catch(e){java.lang.System.out.println("Nashorn15.4 is required for Array.prototype.flat implementation.");} -} -/** -The Object.entries() static method returns an array of a given object's own enumerable string-keyed property key-value pairs. -ECMAScript 2017 -*/ -if (Object.entries==null){ - try{ - eval("Object.entries=function(e){var r,t=Object.keys(e);return{[Symbol.iterator](){return this},next:()=>void 0!==(r=t.shift())?{value:[r,e[r]]}:{done:!0}}},Object.defineProperty(Object,\"entries\",{enumerable:!1});"); - }catch(e){java.lang.System.out.println("Nashorn15.4 is required for Object.entries implementation.");} -} - -/////////////////////////////////////////////////////////////////////////////// -/** -This module mimics the browser's timeout functionality. I added it to make Promise work. -Idears from https://github.com/nikku/nashorn-async -*/ -(function(context){ - if (context.setTimeout==null){ - var timer = new java.util.Timer(); - function setTimeout(fn, millis/*,...args*/) { - var args=[]; - for (var i=2; i>>16&65535)*r+n*(e>>>16&65535)<<16>>>0)|0},Object.defineProperty(Math,"imul",{enumerable:!1})),null==Math.fround&&(Math.fround=function(t){var e=new Float32Array(1);return e[0]=t,e[0]},Object.defineProperty(Math,"fround",{enumerable:!1})),null==Math.clz32&&(Math.clz32=function(t){t>>>=0;return 0==t?32:31-(Math.log(t)/Math.LN2|0)|0},Object.defineProperty(Math,"clz32",{enumerable:!1})),null==Number.EPSILON&&(Number.EPSILON=2220446049250313e-31,Object.defineProperty(Number,"EPSILON",{enumerable:!1})),null==Number.isFinite&&(Number.isFinite=function(t){return"number"==typeof t&&isFinite(t)},Object.defineProperty(Number,"isFinite",{enumerable:!1})),null==Number.isInteger&&(Number.isInteger=function(t){return"number"==typeof t&&t%1==0},Object.defineProperty(Number,"isInteger",{enumerable:!1})),null==Number.isNaN&&(Number.isNaN=function(t){return t!=t},Object.defineProperty(Number,"isNaN",{enumerable:!1})),null==Number.parseFloat&&(Number.parseFloat=function(t){return parseFloat(t)},Object.defineProperty(Number,"parseFloat",{enumerable:!1})),null==Number.parseInt&&(Number.parseInt=function(t,e){return parseInt(t,e)},Object.defineProperty(Number,"parseInt",{enumerable:!1})),null==String.prototype.codePointAt&&(String.prototype.codePointAt=function(t){for(var e=String(this),n=e.length,r=0,u=0,o=0,u=0;u>10)),e.push(56320+(1023&t)));return String.fromCharCode.apply(null,e)},Object.defineProperty(String,"fromCodePoint",{enumerable:!1})),null==String.prototype.includes&&(String.prototype.includes=function(t,e){return null==e&&(e=0),-10?t=t.concat(e.flat(r-1)):t.push(e);return t},Object.defineProperty(Array.prototype,"flat",{enumerable:!1});')}catch(e){java.lang.System.out.println("Nashorn15.4 is required for Array.prototype.flat implementation.")}if(null==Object.entries)try{eval('Object.entries=function(e){var r,t=Object.keys(e);return{[Symbol.iterator](){return this},next:()=>void 0!==(r=t.shift())?{value:[r,e[r]]}:{done:!0}}},Object.defineProperty(Object,"entries",{enumerable:!1});')}catch(e){java.lang.System.out.println("Nashorn15.4 is required for Object.entries implementation.")}!function(t){var o;null==t.setTimeout&&(o=new java.util.Timer,t.setTimeout=function(t,e){for(var n=[],r=2;r