diff --git a/package.json b/package.json index 0850262..71dab27 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "type": "module", "scripts": { - "build": "deno build.ts --tagName 1.66.5b0 > ubo.js", + "build": "deno build.ts --tagName 1.66.5b2 > ubo.js", "test": "node --test" }, "author": { diff --git a/ubo.js b/ubo.js index 8023ab4..3895c67 100644 --- a/ubo.js +++ b/ubo.js @@ -1885,6 +1885,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -1897,7 +1901,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -2206,7 +2210,7 @@ class JSONPath { continue; } if ( c0 === 0x27 /* ' */ ) { - const r = this.#consumeQuotedIdentifier(query, i+1); + const r = this.#untilChar(query, 0x27 /* ' */, i+1) if ( r === undefined ) { return; } keys.push(r.s); i = r.i; @@ -2227,22 +2231,27 @@ class JSONPath { } return { s: keys.length === 1 ? keys[0] : keys, i }; } - #consumeQuotedIdentifier(query, i) { + #consumeUnquotedIdentifier(query, i) { + const match = this.#reUnquotedIdentifier.exec(query.slice(i)); + if ( match === null ) { return; } + return match[0]; + } + #untilChar(query, targetCharCode, i) { const len = query.length; const parts = []; let beg = i, end = i; for (;;) { if ( end === len ) { return; } const c = query.charCodeAt(end); - if ( c === 0x27 /* ' */ ) { + if ( c === targetCharCode ) { parts.push(query.slice(beg, end)); end += 1; break; } if ( c === 0x5C /* \ */ && (end+1) < len ) { parts.push(query.slice(beg, end)); - const d = query.chatCodeAt(end+1); - if ( d === 0x27 || d === 0x5C ) { + const d = query.charCodeAt(end+1); + if ( d === targetCharCode || d === 0x5C ) { end += 1; beg = end; } @@ -2251,12 +2260,20 @@ class JSONPath { } return { s: parts.join(''), i: end }; } - #consumeUnquotedIdentifier(query, i) { - const match = this.#reUnquotedIdentifier.exec(query.slice(i)); - if ( match === null ) { return; } - return match[0]; - } #compileExpr(query, step, i) { + if ( query.startsWith('=/', i) ) { + const r = this.#untilChar(query, 0x2F /* / */, i+2); + if ( r === undefined ) { return i; } + const match = /^[i]/.exec(query.slice(r.i)); + try { + step.rval = new RegExp(r.s, match && match[0] || undefined); + } catch { + return i; + } + step.op = 're'; + if ( match ) { r.i += match[0].length; } + return r.i; + } const match = this.#reExpr.exec(query.slice(i)); if ( match === null ) { return i; } try { @@ -2296,6 +2313,7 @@ class JSONPath { case '^=': outcome = `${v}`.startsWith(step.rval) === target; break; case '$=': outcome = `${v}`.endsWith(step.rval) === target; break; case '*=': outcome = `${v}`.includes(step.rval) === target; break; + case 're': outcome = step.rval.test(`${v}`); break; default: outcome = hasOwn === target; break; } if ( outcome ) { return k; } @@ -2627,6 +2645,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -2639,7 +2661,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -2948,7 +2970,7 @@ class JSONPath { continue; } if ( c0 === 0x27 /* ' */ ) { - const r = this.#consumeQuotedIdentifier(query, i+1); + const r = this.#untilChar(query, 0x27 /* ' */, i+1) if ( r === undefined ) { return; } keys.push(r.s); i = r.i; @@ -2969,22 +2991,27 @@ class JSONPath { } return { s: keys.length === 1 ? keys[0] : keys, i }; } - #consumeQuotedIdentifier(query, i) { + #consumeUnquotedIdentifier(query, i) { + const match = this.#reUnquotedIdentifier.exec(query.slice(i)); + if ( match === null ) { return; } + return match[0]; + } + #untilChar(query, targetCharCode, i) { const len = query.length; const parts = []; let beg = i, end = i; for (;;) { if ( end === len ) { return; } const c = query.charCodeAt(end); - if ( c === 0x27 /* ' */ ) { + if ( c === targetCharCode ) { parts.push(query.slice(beg, end)); end += 1; break; } if ( c === 0x5C /* \ */ && (end+1) < len ) { parts.push(query.slice(beg, end)); - const d = query.chatCodeAt(end+1); - if ( d === 0x27 || d === 0x5C ) { + const d = query.charCodeAt(end+1); + if ( d === targetCharCode || d === 0x5C ) { end += 1; beg = end; } @@ -2993,12 +3020,20 @@ class JSONPath { } return { s: parts.join(''), i: end }; } - #consumeUnquotedIdentifier(query, i) { - const match = this.#reUnquotedIdentifier.exec(query.slice(i)); - if ( match === null ) { return; } - return match[0]; - } #compileExpr(query, step, i) { + if ( query.startsWith('=/', i) ) { + const r = this.#untilChar(query, 0x2F /* / */, i+2); + if ( r === undefined ) { return i; } + const match = /^[i]/.exec(query.slice(r.i)); + try { + step.rval = new RegExp(r.s, match && match[0] || undefined); + } catch { + return i; + } + step.op = 're'; + if ( match ) { r.i += match[0].length; } + return r.i; + } const match = this.#reExpr.exec(query.slice(i)); if ( match === null ) { return i; } try { @@ -3038,6 +3073,7 @@ class JSONPath { case '^=': outcome = `${v}`.startsWith(step.rval) === target; break; case '$=': outcome = `${v}`.endsWith(step.rval) === target; break; case '*=': outcome = `${v}`.includes(step.rval) === target; break; + case 're': outcome = step.rval.test(`${v}`); break; default: outcome = hasOwn === target; break; } if ( outcome ) { return k; } @@ -3369,6 +3405,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -3381,7 +3421,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -3690,7 +3730,7 @@ class JSONPath { continue; } if ( c0 === 0x27 /* ' */ ) { - const r = this.#consumeQuotedIdentifier(query, i+1); + const r = this.#untilChar(query, 0x27 /* ' */, i+1) if ( r === undefined ) { return; } keys.push(r.s); i = r.i; @@ -3711,22 +3751,27 @@ class JSONPath { } return { s: keys.length === 1 ? keys[0] : keys, i }; } - #consumeQuotedIdentifier(query, i) { + #consumeUnquotedIdentifier(query, i) { + const match = this.#reUnquotedIdentifier.exec(query.slice(i)); + if ( match === null ) { return; } + return match[0]; + } + #untilChar(query, targetCharCode, i) { const len = query.length; const parts = []; let beg = i, end = i; for (;;) { if ( end === len ) { return; } const c = query.charCodeAt(end); - if ( c === 0x27 /* ' */ ) { + if ( c === targetCharCode ) { parts.push(query.slice(beg, end)); end += 1; break; } if ( c === 0x5C /* \ */ && (end+1) < len ) { parts.push(query.slice(beg, end)); - const d = query.chatCodeAt(end+1); - if ( d === 0x27 || d === 0x5C ) { + const d = query.charCodeAt(end+1); + if ( d === targetCharCode || d === 0x5C ) { end += 1; beg = end; } @@ -3735,12 +3780,20 @@ class JSONPath { } return { s: parts.join(''), i: end }; } - #consumeUnquotedIdentifier(query, i) { - const match = this.#reUnquotedIdentifier.exec(query.slice(i)); - if ( match === null ) { return; } - return match[0]; - } #compileExpr(query, step, i) { + if ( query.startsWith('=/', i) ) { + const r = this.#untilChar(query, 0x2F /* / */, i+2); + if ( r === undefined ) { return i; } + const match = /^[i]/.exec(query.slice(r.i)); + try { + step.rval = new RegExp(r.s, match && match[0] || undefined); + } catch { + return i; + } + step.op = 're'; + if ( match ) { r.i += match[0].length; } + return r.i; + } const match = this.#reExpr.exec(query.slice(i)); if ( match === null ) { return i; } try { @@ -3780,6 +3833,7 @@ class JSONPath { case '^=': outcome = `${v}`.startsWith(step.rval) === target; break; case '$=': outcome = `${v}`.endsWith(step.rval) === target; break; case '*=': outcome = `${v}`.includes(step.rval) === target; break; + case 're': outcome = step.rval.test(`${v}`); break; default: outcome = hasOwn === target; break; } if ( outcome ) { return k; } @@ -4111,6 +4165,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -4123,7 +4181,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -4432,7 +4490,7 @@ class JSONPath { continue; } if ( c0 === 0x27 /* ' */ ) { - const r = this.#consumeQuotedIdentifier(query, i+1); + const r = this.#untilChar(query, 0x27 /* ' */, i+1) if ( r === undefined ) { return; } keys.push(r.s); i = r.i; @@ -4453,22 +4511,27 @@ class JSONPath { } return { s: keys.length === 1 ? keys[0] : keys, i }; } - #consumeQuotedIdentifier(query, i) { + #consumeUnquotedIdentifier(query, i) { + const match = this.#reUnquotedIdentifier.exec(query.slice(i)); + if ( match === null ) { return; } + return match[0]; + } + #untilChar(query, targetCharCode, i) { const len = query.length; const parts = []; let beg = i, end = i; for (;;) { if ( end === len ) { return; } const c = query.charCodeAt(end); - if ( c === 0x27 /* ' */ ) { + if ( c === targetCharCode ) { parts.push(query.slice(beg, end)); end += 1; break; } if ( c === 0x5C /* \ */ && (end+1) < len ) { parts.push(query.slice(beg, end)); - const d = query.chatCodeAt(end+1); - if ( d === 0x27 || d === 0x5C ) { + const d = query.charCodeAt(end+1); + if ( d === targetCharCode || d === 0x5C ) { end += 1; beg = end; } @@ -4477,12 +4540,20 @@ class JSONPath { } return { s: parts.join(''), i: end }; } - #consumeUnquotedIdentifier(query, i) { - const match = this.#reUnquotedIdentifier.exec(query.slice(i)); - if ( match === null ) { return; } - return match[0]; - } #compileExpr(query, step, i) { + if ( query.startsWith('=/', i) ) { + const r = this.#untilChar(query, 0x2F /* / */, i+2); + if ( r === undefined ) { return i; } + const match = /^[i]/.exec(query.slice(r.i)); + try { + step.rval = new RegExp(r.s, match && match[0] || undefined); + } catch { + return i; + } + step.op = 're'; + if ( match ) { r.i += match[0].length; } + return r.i; + } const match = this.#reExpr.exec(query.slice(i)); if ( match === null ) { return i; } try { @@ -4522,6 +4593,7 @@ class JSONPath { case '^=': outcome = `${v}`.startsWith(step.rval) === target; break; case '$=': outcome = `${v}`.endsWith(step.rval) === target; break; case '*=': outcome = `${v}`.includes(step.rval) === target; break; + case 're': outcome = step.rval.test(`${v}`); break; default: outcome = hasOwn === target; break; } if ( outcome ) { return k; } @@ -4853,6 +4925,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -4865,7 +4941,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -5174,7 +5250,7 @@ class JSONPath { continue; } if ( c0 === 0x27 /* ' */ ) { - const r = this.#consumeQuotedIdentifier(query, i+1); + const r = this.#untilChar(query, 0x27 /* ' */, i+1) if ( r === undefined ) { return; } keys.push(r.s); i = r.i; @@ -5195,22 +5271,27 @@ class JSONPath { } return { s: keys.length === 1 ? keys[0] : keys, i }; } - #consumeQuotedIdentifier(query, i) { + #consumeUnquotedIdentifier(query, i) { + const match = this.#reUnquotedIdentifier.exec(query.slice(i)); + if ( match === null ) { return; } + return match[0]; + } + #untilChar(query, targetCharCode, i) { const len = query.length; const parts = []; let beg = i, end = i; for (;;) { if ( end === len ) { return; } const c = query.charCodeAt(end); - if ( c === 0x27 /* ' */ ) { + if ( c === targetCharCode ) { parts.push(query.slice(beg, end)); end += 1; break; } if ( c === 0x5C /* \ */ && (end+1) < len ) { parts.push(query.slice(beg, end)); - const d = query.chatCodeAt(end+1); - if ( d === 0x27 || d === 0x5C ) { + const d = query.charCodeAt(end+1); + if ( d === targetCharCode || d === 0x5C ) { end += 1; beg = end; } @@ -5219,12 +5300,20 @@ class JSONPath { } return { s: parts.join(''), i: end }; } - #consumeUnquotedIdentifier(query, i) { - const match = this.#reUnquotedIdentifier.exec(query.slice(i)); - if ( match === null ) { return; } - return match[0]; - } #compileExpr(query, step, i) { + if ( query.startsWith('=/', i) ) { + const r = this.#untilChar(query, 0x2F /* / */, i+2); + if ( r === undefined ) { return i; } + const match = /^[i]/.exec(query.slice(r.i)); + try { + step.rval = new RegExp(r.s, match && match[0] || undefined); + } catch { + return i; + } + step.op = 're'; + if ( match ) { r.i += match[0].length; } + return r.i; + } const match = this.#reExpr.exec(query.slice(i)); if ( match === null ) { return i; } try { @@ -5264,6 +5353,7 @@ class JSONPath { case '^=': outcome = `${v}`.startsWith(step.rval) === target; break; case '$=': outcome = `${v}`.endsWith(step.rval) === target; break; case '*=': outcome = `${v}`.includes(step.rval) === target; break; + case 're': outcome = step.rval.test(`${v}`); break; default: outcome = hasOwn === target; break; } if ( outcome ) { return k; } @@ -5348,11 +5438,11 @@ function editInboundObjectFn( return objAfter; }; proxyApplyFn(propChain, function(context) { - const i = getArgPos(context.args); + const i = getArgPos(context.callArgs); if ( i !== undefined ) { - const obj = editObj(context.args[i]); + const obj = editObj(context.callArgs[i]); if ( obj ) { - context.args[i] = obj; + context.callArgs[i] = obj; } } return context.reflect(); @@ -5621,6 +5711,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -5633,7 +5727,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -5942,7 +6036,7 @@ class JSONPath { continue; } if ( c0 === 0x27 /* ' */ ) { - const r = this.#consumeQuotedIdentifier(query, i+1); + const r = this.#untilChar(query, 0x27 /* ' */, i+1) if ( r === undefined ) { return; } keys.push(r.s); i = r.i; @@ -5963,22 +6057,27 @@ class JSONPath { } return { s: keys.length === 1 ? keys[0] : keys, i }; } - #consumeQuotedIdentifier(query, i) { + #consumeUnquotedIdentifier(query, i) { + const match = this.#reUnquotedIdentifier.exec(query.slice(i)); + if ( match === null ) { return; } + return match[0]; + } + #untilChar(query, targetCharCode, i) { const len = query.length; const parts = []; let beg = i, end = i; for (;;) { if ( end === len ) { return; } const c = query.charCodeAt(end); - if ( c === 0x27 /* ' */ ) { + if ( c === targetCharCode ) { parts.push(query.slice(beg, end)); end += 1; break; } if ( c === 0x5C /* \ */ && (end+1) < len ) { parts.push(query.slice(beg, end)); - const d = query.chatCodeAt(end+1); - if ( d === 0x27 || d === 0x5C ) { + const d = query.charCodeAt(end+1); + if ( d === targetCharCode || d === 0x5C ) { end += 1; beg = end; } @@ -5987,12 +6086,20 @@ class JSONPath { } return { s: parts.join(''), i: end }; } - #consumeUnquotedIdentifier(query, i) { - const match = this.#reUnquotedIdentifier.exec(query.slice(i)); - if ( match === null ) { return; } - return match[0]; - } #compileExpr(query, step, i) { + if ( query.startsWith('=/', i) ) { + const r = this.#untilChar(query, 0x2F /* / */, i+2); + if ( r === undefined ) { return i; } + const match = /^[i]/.exec(query.slice(r.i)); + try { + step.rval = new RegExp(r.s, match && match[0] || undefined); + } catch { + return i; + } + step.op = 're'; + if ( match ) { r.i += match[0].length; } + return r.i; + } const match = this.#reExpr.exec(query.slice(i)); if ( match === null ) { return i; } try { @@ -6032,6 +6139,7 @@ class JSONPath { case '^=': outcome = `${v}`.startsWith(step.rval) === target; break; case '$=': outcome = `${v}`.endsWith(step.rval) === target; break; case '*=': outcome = `${v}`.includes(step.rval) === target; break; + case 're': outcome = step.rval.test(`${v}`); break; default: outcome = hasOwn === target; break; } if ( outcome ) { return k; } @@ -6116,11 +6224,11 @@ function editInboundObjectFn( return objAfter; }; proxyApplyFn(propChain, function(context) { - const i = getArgPos(context.args); + const i = getArgPos(context.callArgs); if ( i !== undefined ) { - const obj = editObj(context.args[i]); + const obj = editObj(context.callArgs[i]); if ( obj ) { - context.args[i] = obj; + context.callArgs[i] = obj; } } return context.reflect(); @@ -6669,7 +6777,7 @@ class JSONPath { continue; } if ( c0 === 0x27 /* ' */ ) { - const r = this.#consumeQuotedIdentifier(query, i+1); + const r = this.#untilChar(query, 0x27 /* ' */, i+1) if ( r === undefined ) { return; } keys.push(r.s); i = r.i; @@ -6690,22 +6798,27 @@ class JSONPath { } return { s: keys.length === 1 ? keys[0] : keys, i }; } - #consumeQuotedIdentifier(query, i) { + #consumeUnquotedIdentifier(query, i) { + const match = this.#reUnquotedIdentifier.exec(query.slice(i)); + if ( match === null ) { return; } + return match[0]; + } + #untilChar(query, targetCharCode, i) { const len = query.length; const parts = []; let beg = i, end = i; for (;;) { if ( end === len ) { return; } const c = query.charCodeAt(end); - if ( c === 0x27 /* ' */ ) { + if ( c === targetCharCode ) { parts.push(query.slice(beg, end)); end += 1; break; } if ( c === 0x5C /* \ */ && (end+1) < len ) { parts.push(query.slice(beg, end)); - const d = query.chatCodeAt(end+1); - if ( d === 0x27 || d === 0x5C ) { + const d = query.charCodeAt(end+1); + if ( d === targetCharCode || d === 0x5C ) { end += 1; beg = end; } @@ -6714,12 +6827,20 @@ class JSONPath { } return { s: parts.join(''), i: end }; } - #consumeUnquotedIdentifier(query, i) { - const match = this.#reUnquotedIdentifier.exec(query.slice(i)); - if ( match === null ) { return; } - return match[0]; - } #compileExpr(query, step, i) { + if ( query.startsWith('=/', i) ) { + const r = this.#untilChar(query, 0x2F /* / */, i+2); + if ( r === undefined ) { return i; } + const match = /^[i]/.exec(query.slice(r.i)); + try { + step.rval = new RegExp(r.s, match && match[0] || undefined); + } catch { + return i; + } + step.op = 're'; + if ( match ) { r.i += match[0].length; } + return r.i; + } const match = this.#reExpr.exec(query.slice(i)); if ( match === null ) { return i; } try { @@ -6759,6 +6880,7 @@ class JSONPath { case '^=': outcome = `${v}`.startsWith(step.rval) === target; break; case '$=': outcome = `${v}`.endsWith(step.rval) === target; break; case '*=': outcome = `${v}`.includes(step.rval) === target; break; + case 're': outcome = step.rval.test(`${v}`); break; default: outcome = hasOwn === target; break; } if ( outcome ) { return k; } @@ -7410,7 +7532,7 @@ class JSONPath { continue; } if ( c0 === 0x27 /* ' */ ) { - const r = this.#consumeQuotedIdentifier(query, i+1); + const r = this.#untilChar(query, 0x27 /* ' */, i+1) if ( r === undefined ) { return; } keys.push(r.s); i = r.i; @@ -7431,22 +7553,27 @@ class JSONPath { } return { s: keys.length === 1 ? keys[0] : keys, i }; } - #consumeQuotedIdentifier(query, i) { + #consumeUnquotedIdentifier(query, i) { + const match = this.#reUnquotedIdentifier.exec(query.slice(i)); + if ( match === null ) { return; } + return match[0]; + } + #untilChar(query, targetCharCode, i) { const len = query.length; const parts = []; let beg = i, end = i; for (;;) { if ( end === len ) { return; } const c = query.charCodeAt(end); - if ( c === 0x27 /* ' */ ) { + if ( c === targetCharCode ) { parts.push(query.slice(beg, end)); end += 1; break; } if ( c === 0x5C /* \ */ && (end+1) < len ) { parts.push(query.slice(beg, end)); - const d = query.chatCodeAt(end+1); - if ( d === 0x27 || d === 0x5C ) { + const d = query.charCodeAt(end+1); + if ( d === targetCharCode || d === 0x5C ) { end += 1; beg = end; } @@ -7455,12 +7582,20 @@ class JSONPath { } return { s: parts.join(''), i: end }; } - #consumeUnquotedIdentifier(query, i) { - const match = this.#reUnquotedIdentifier.exec(query.slice(i)); - if ( match === null ) { return; } - return match[0]; - } #compileExpr(query, step, i) { + if ( query.startsWith('=/', i) ) { + const r = this.#untilChar(query, 0x2F /* / */, i+2); + if ( r === undefined ) { return i; } + const match = /^[i]/.exec(query.slice(r.i)); + try { + step.rval = new RegExp(r.s, match && match[0] || undefined); + } catch { + return i; + } + step.op = 're'; + if ( match ) { r.i += match[0].length; } + return r.i; + } const match = this.#reExpr.exec(query.slice(i)); if ( match === null ) { return i; } try { @@ -7500,6 +7635,7 @@ class JSONPath { case '^=': outcome = `${v}`.startsWith(step.rval) === target; break; case '$=': outcome = `${v}`.endsWith(step.rval) === target; break; case '*=': outcome = `${v}`.includes(step.rval) === target; break; + case 're': outcome = step.rval.test(`${v}`); break; default: outcome = hasOwn === target; break; } if ( outcome ) { return k; } @@ -8151,7 +8287,7 @@ class JSONPath { continue; } if ( c0 === 0x27 /* ' */ ) { - const r = this.#consumeQuotedIdentifier(query, i+1); + const r = this.#untilChar(query, 0x27 /* ' */, i+1) if ( r === undefined ) { return; } keys.push(r.s); i = r.i; @@ -8172,22 +8308,27 @@ class JSONPath { } return { s: keys.length === 1 ? keys[0] : keys, i }; } - #consumeQuotedIdentifier(query, i) { + #consumeUnquotedIdentifier(query, i) { + const match = this.#reUnquotedIdentifier.exec(query.slice(i)); + if ( match === null ) { return; } + return match[0]; + } + #untilChar(query, targetCharCode, i) { const len = query.length; const parts = []; let beg = i, end = i; for (;;) { if ( end === len ) { return; } const c = query.charCodeAt(end); - if ( c === 0x27 /* ' */ ) { + if ( c === targetCharCode ) { parts.push(query.slice(beg, end)); end += 1; break; } if ( c === 0x5C /* \ */ && (end+1) < len ) { parts.push(query.slice(beg, end)); - const d = query.chatCodeAt(end+1); - if ( d === 0x27 || d === 0x5C ) { + const d = query.charCodeAt(end+1); + if ( d === targetCharCode || d === 0x5C ) { end += 1; beg = end; } @@ -8196,12 +8337,20 @@ class JSONPath { } return { s: parts.join(''), i: end }; } - #consumeUnquotedIdentifier(query, i) { - const match = this.#reUnquotedIdentifier.exec(query.slice(i)); - if ( match === null ) { return; } - return match[0]; - } #compileExpr(query, step, i) { + if ( query.startsWith('=/', i) ) { + const r = this.#untilChar(query, 0x2F /* / */, i+2); + if ( r === undefined ) { return i; } + const match = /^[i]/.exec(query.slice(r.i)); + try { + step.rval = new RegExp(r.s, match && match[0] || undefined); + } catch { + return i; + } + step.op = 're'; + if ( match ) { r.i += match[0].length; } + return r.i; + } const match = this.#reExpr.exec(query.slice(i)); if ( match === null ) { return i; } try { @@ -8241,6 +8390,7 @@ class JSONPath { case '^=': outcome = `${v}`.startsWith(step.rval) === target; break; case '$=': outcome = `${v}`.endsWith(step.rval) === target; break; case '*=': outcome = `${v}`.includes(step.rval) === target; break; + case 're': outcome = step.rval.test(`${v}`); break; default: outcome = hasOwn === target; break; } if ( outcome ) { return k; } @@ -8875,7 +9025,7 @@ class JSONPath { continue; } if ( c0 === 0x27 /* ' */ ) { - const r = this.#consumeQuotedIdentifier(query, i+1); + const r = this.#untilChar(query, 0x27 /* ' */, i+1) if ( r === undefined ) { return; } keys.push(r.s); i = r.i; @@ -8896,22 +9046,27 @@ class JSONPath { } return { s: keys.length === 1 ? keys[0] : keys, i }; } - #consumeQuotedIdentifier(query, i) { + #consumeUnquotedIdentifier(query, i) { + const match = this.#reUnquotedIdentifier.exec(query.slice(i)); + if ( match === null ) { return; } + return match[0]; + } + #untilChar(query, targetCharCode, i) { const len = query.length; const parts = []; let beg = i, end = i; for (;;) { if ( end === len ) { return; } const c = query.charCodeAt(end); - if ( c === 0x27 /* ' */ ) { + if ( c === targetCharCode ) { parts.push(query.slice(beg, end)); end += 1; break; } if ( c === 0x5C /* \ */ && (end+1) < len ) { parts.push(query.slice(beg, end)); - const d = query.chatCodeAt(end+1); - if ( d === 0x27 || d === 0x5C ) { + const d = query.charCodeAt(end+1); + if ( d === targetCharCode || d === 0x5C ) { end += 1; beg = end; } @@ -8920,12 +9075,20 @@ class JSONPath { } return { s: parts.join(''), i: end }; } - #consumeUnquotedIdentifier(query, i) { - const match = this.#reUnquotedIdentifier.exec(query.slice(i)); - if ( match === null ) { return; } - return match[0]; - } #compileExpr(query, step, i) { + if ( query.startsWith('=/', i) ) { + const r = this.#untilChar(query, 0x2F /* / */, i+2); + if ( r === undefined ) { return i; } + const match = /^[i]/.exec(query.slice(r.i)); + try { + step.rval = new RegExp(r.s, match && match[0] || undefined); + } catch { + return i; + } + step.op = 're'; + if ( match ) { r.i += match[0].length; } + return r.i; + } const match = this.#reExpr.exec(query.slice(i)); if ( match === null ) { return i; } try { @@ -8965,6 +9128,7 @@ class JSONPath { case '^=': outcome = `${v}`.startsWith(step.rval) === target; break; case '$=': outcome = `${v}`.endsWith(step.rval) === target; break; case '*=': outcome = `${v}`.includes(step.rval) === target; break; + case 're': outcome = step.rval.test(`${v}`); break; default: outcome = hasOwn === target; break; } if ( outcome ) { return k; } @@ -9130,6 +9294,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -9142,7 +9310,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -9679,7 +9847,7 @@ class JSONPath { continue; } if ( c0 === 0x27 /* ' */ ) { - const r = this.#consumeQuotedIdentifier(query, i+1); + const r = this.#untilChar(query, 0x27 /* ' */, i+1) if ( r === undefined ) { return; } keys.push(r.s); i = r.i; @@ -9700,22 +9868,27 @@ class JSONPath { } return { s: keys.length === 1 ? keys[0] : keys, i }; } - #consumeQuotedIdentifier(query, i) { + #consumeUnquotedIdentifier(query, i) { + const match = this.#reUnquotedIdentifier.exec(query.slice(i)); + if ( match === null ) { return; } + return match[0]; + } + #untilChar(query, targetCharCode, i) { const len = query.length; const parts = []; let beg = i, end = i; for (;;) { if ( end === len ) { return; } const c = query.charCodeAt(end); - if ( c === 0x27 /* ' */ ) { + if ( c === targetCharCode ) { parts.push(query.slice(beg, end)); end += 1; break; } if ( c === 0x5C /* \ */ && (end+1) < len ) { parts.push(query.slice(beg, end)); - const d = query.chatCodeAt(end+1); - if ( d === 0x27 || d === 0x5C ) { + const d = query.charCodeAt(end+1); + if ( d === targetCharCode || d === 0x5C ) { end += 1; beg = end; } @@ -9724,12 +9897,20 @@ class JSONPath { } return { s: parts.join(''), i: end }; } - #consumeUnquotedIdentifier(query, i) { - const match = this.#reUnquotedIdentifier.exec(query.slice(i)); - if ( match === null ) { return; } - return match[0]; - } #compileExpr(query, step, i) { + if ( query.startsWith('=/', i) ) { + const r = this.#untilChar(query, 0x2F /* / */, i+2); + if ( r === undefined ) { return i; } + const match = /^[i]/.exec(query.slice(r.i)); + try { + step.rval = new RegExp(r.s, match && match[0] || undefined); + } catch { + return i; + } + step.op = 're'; + if ( match ) { r.i += match[0].length; } + return r.i; + } const match = this.#reExpr.exec(query.slice(i)); if ( match === null ) { return i; } try { @@ -9769,6 +9950,7 @@ class JSONPath { case '^=': outcome = `${v}`.startsWith(step.rval) === target; break; case '$=': outcome = `${v}`.endsWith(step.rval) === target; break; case '*=': outcome = `${v}`.includes(step.rval) === target; break; + case 're': outcome = step.rval.test(`${v}`); break; default: outcome = hasOwn === target; break; } if ( outcome ) { return k; } @@ -9946,6 +10128,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -9958,7 +10144,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -10495,7 +10681,7 @@ class JSONPath { continue; } if ( c0 === 0x27 /* ' */ ) { - const r = this.#consumeQuotedIdentifier(query, i+1); + const r = this.#untilChar(query, 0x27 /* ' */, i+1) if ( r === undefined ) { return; } keys.push(r.s); i = r.i; @@ -10516,22 +10702,27 @@ class JSONPath { } return { s: keys.length === 1 ? keys[0] : keys, i }; } - #consumeQuotedIdentifier(query, i) { + #consumeUnquotedIdentifier(query, i) { + const match = this.#reUnquotedIdentifier.exec(query.slice(i)); + if ( match === null ) { return; } + return match[0]; + } + #untilChar(query, targetCharCode, i) { const len = query.length; const parts = []; let beg = i, end = i; for (;;) { if ( end === len ) { return; } const c = query.charCodeAt(end); - if ( c === 0x27 /* ' */ ) { + if ( c === targetCharCode ) { parts.push(query.slice(beg, end)); end += 1; break; } if ( c === 0x5C /* \ */ && (end+1) < len ) { parts.push(query.slice(beg, end)); - const d = query.chatCodeAt(end+1); - if ( d === 0x27 || d === 0x5C ) { + const d = query.charCodeAt(end+1); + if ( d === targetCharCode || d === 0x5C ) { end += 1; beg = end; } @@ -10540,12 +10731,20 @@ class JSONPath { } return { s: parts.join(''), i: end }; } - #consumeUnquotedIdentifier(query, i) { - const match = this.#reUnquotedIdentifier.exec(query.slice(i)); - if ( match === null ) { return; } - return match[0]; - } #compileExpr(query, step, i) { + if ( query.startsWith('=/', i) ) { + const r = this.#untilChar(query, 0x2F /* / */, i+2); + if ( r === undefined ) { return i; } + const match = /^[i]/.exec(query.slice(r.i)); + try { + step.rval = new RegExp(r.s, match && match[0] || undefined); + } catch { + return i; + } + step.op = 're'; + if ( match ) { r.i += match[0].length; } + return r.i; + } const match = this.#reExpr.exec(query.slice(i)); if ( match === null ) { return i; } try { @@ -10585,6 +10784,7 @@ class JSONPath { case '^=': outcome = `${v}`.startsWith(step.rval) === target; break; case '$=': outcome = `${v}`.endsWith(step.rval) === target; break; case '*=': outcome = `${v}`.includes(step.rval) === target; break; + case 're': outcome = step.rval.test(`${v}`); break; default: outcome = hasOwn === target; break; } if ( outcome ) { return k; } @@ -10762,6 +10962,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -10774,7 +10978,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -11311,7 +11515,7 @@ class JSONPath { continue; } if ( c0 === 0x27 /* ' */ ) { - const r = this.#consumeQuotedIdentifier(query, i+1); + const r = this.#untilChar(query, 0x27 /* ' */, i+1) if ( r === undefined ) { return; } keys.push(r.s); i = r.i; @@ -11332,22 +11536,27 @@ class JSONPath { } return { s: keys.length === 1 ? keys[0] : keys, i }; } - #consumeQuotedIdentifier(query, i) { + #consumeUnquotedIdentifier(query, i) { + const match = this.#reUnquotedIdentifier.exec(query.slice(i)); + if ( match === null ) { return; } + return match[0]; + } + #untilChar(query, targetCharCode, i) { const len = query.length; const parts = []; let beg = i, end = i; for (;;) { if ( end === len ) { return; } const c = query.charCodeAt(end); - if ( c === 0x27 /* ' */ ) { + if ( c === targetCharCode ) { parts.push(query.slice(beg, end)); end += 1; break; } if ( c === 0x5C /* \ */ && (end+1) < len ) { parts.push(query.slice(beg, end)); - const d = query.chatCodeAt(end+1); - if ( d === 0x27 || d === 0x5C ) { + const d = query.charCodeAt(end+1); + if ( d === targetCharCode || d === 0x5C ) { end += 1; beg = end; } @@ -11356,12 +11565,20 @@ class JSONPath { } return { s: parts.join(''), i: end }; } - #consumeUnquotedIdentifier(query, i) { - const match = this.#reUnquotedIdentifier.exec(query.slice(i)); - if ( match === null ) { return; } - return match[0]; - } #compileExpr(query, step, i) { + if ( query.startsWith('=/', i) ) { + const r = this.#untilChar(query, 0x2F /* / */, i+2); + if ( r === undefined ) { return i; } + const match = /^[i]/.exec(query.slice(r.i)); + try { + step.rval = new RegExp(r.s, match && match[0] || undefined); + } catch { + return i; + } + step.op = 're'; + if ( match ) { r.i += match[0].length; } + return r.i; + } const match = this.#reExpr.exec(query.slice(i)); if ( match === null ) { return i; } try { @@ -11401,6 +11618,7 @@ class JSONPath { case '^=': outcome = `${v}`.startsWith(step.rval) === target; break; case '$=': outcome = `${v}`.endsWith(step.rval) === target; break; case '*=': outcome = `${v}`.includes(step.rval) === target; break; + case 're': outcome = step.rval.test(`${v}`); break; default: outcome = hasOwn === target; break; } if ( outcome ) { return k; } @@ -11574,6 +11792,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -11586,7 +11808,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -12123,7 +12345,7 @@ class JSONPath { continue; } if ( c0 === 0x27 /* ' */ ) { - const r = this.#consumeQuotedIdentifier(query, i+1); + const r = this.#untilChar(query, 0x27 /* ' */, i+1) if ( r === undefined ) { return; } keys.push(r.s); i = r.i; @@ -12144,22 +12366,27 @@ class JSONPath { } return { s: keys.length === 1 ? keys[0] : keys, i }; } - #consumeQuotedIdentifier(query, i) { + #consumeUnquotedIdentifier(query, i) { + const match = this.#reUnquotedIdentifier.exec(query.slice(i)); + if ( match === null ) { return; } + return match[0]; + } + #untilChar(query, targetCharCode, i) { const len = query.length; const parts = []; let beg = i, end = i; for (;;) { if ( end === len ) { return; } const c = query.charCodeAt(end); - if ( c === 0x27 /* ' */ ) { + if ( c === targetCharCode ) { parts.push(query.slice(beg, end)); end += 1; break; } if ( c === 0x5C /* \ */ && (end+1) < len ) { parts.push(query.slice(beg, end)); - const d = query.chatCodeAt(end+1); - if ( d === 0x27 || d === 0x5C ) { + const d = query.charCodeAt(end+1); + if ( d === targetCharCode || d === 0x5C ) { end += 1; beg = end; } @@ -12168,12 +12395,20 @@ class JSONPath { } return { s: parts.join(''), i: end }; } - #consumeUnquotedIdentifier(query, i) { - const match = this.#reUnquotedIdentifier.exec(query.slice(i)); - if ( match === null ) { return; } - return match[0]; - } #compileExpr(query, step, i) { + if ( query.startsWith('=/', i) ) { + const r = this.#untilChar(query, 0x2F /* / */, i+2); + if ( r === undefined ) { return i; } + const match = /^[i]/.exec(query.slice(r.i)); + try { + step.rval = new RegExp(r.s, match && match[0] || undefined); + } catch { + return i; + } + step.op = 're'; + if ( match ) { r.i += match[0].length; } + return r.i; + } const match = this.#reExpr.exec(query.slice(i)); if ( match === null ) { return i; } try { @@ -12213,6 +12448,7 @@ class JSONPath { case '^=': outcome = `${v}`.startsWith(step.rval) === target; break; case '$=': outcome = `${v}`.endsWith(step.rval) === target; break; case '*=': outcome = `${v}`.includes(step.rval) === target; break; + case 're': outcome = step.rval.test(`${v}`); break; default: outcome = hasOwn === target; break; } if ( outcome ) { return k; } @@ -12877,7 +13113,7 @@ class JSONPath { continue; } if ( c0 === 0x27 /* ' */ ) { - const r = this.#consumeQuotedIdentifier(query, i+1); + const r = this.#untilChar(query, 0x27 /* ' */, i+1) if ( r === undefined ) { return; } keys.push(r.s); i = r.i; @@ -12898,22 +13134,27 @@ class JSONPath { } return { s: keys.length === 1 ? keys[0] : keys, i }; } - #consumeQuotedIdentifier(query, i) { + #consumeUnquotedIdentifier(query, i) { + const match = this.#reUnquotedIdentifier.exec(query.slice(i)); + if ( match === null ) { return; } + return match[0]; + } + #untilChar(query, targetCharCode, i) { const len = query.length; const parts = []; let beg = i, end = i; for (;;) { if ( end === len ) { return; } const c = query.charCodeAt(end); - if ( c === 0x27 /* ' */ ) { + if ( c === targetCharCode ) { parts.push(query.slice(beg, end)); end += 1; break; } if ( c === 0x5C /* \ */ && (end+1) < len ) { parts.push(query.slice(beg, end)); - const d = query.chatCodeAt(end+1); - if ( d === 0x27 || d === 0x5C ) { + const d = query.charCodeAt(end+1); + if ( d === targetCharCode || d === 0x5C ) { end += 1; beg = end; } @@ -12922,12 +13163,20 @@ class JSONPath { } return { s: parts.join(''), i: end }; } - #consumeUnquotedIdentifier(query, i) { - const match = this.#reUnquotedIdentifier.exec(query.slice(i)); - if ( match === null ) { return; } - return match[0]; - } #compileExpr(query, step, i) { + if ( query.startsWith('=/', i) ) { + const r = this.#untilChar(query, 0x2F /* / */, i+2); + if ( r === undefined ) { return i; } + const match = /^[i]/.exec(query.slice(r.i)); + try { + step.rval = new RegExp(r.s, match && match[0] || undefined); + } catch { + return i; + } + step.op = 're'; + if ( match ) { r.i += match[0].length; } + return r.i; + } const match = this.#reExpr.exec(query.slice(i)); if ( match === null ) { return i; } try { @@ -12967,6 +13216,7 @@ class JSONPath { case '^=': outcome = `${v}`.startsWith(step.rval) === target; break; case '$=': outcome = `${v}`.endsWith(step.rval) === target; break; case '*=': outcome = `${v}`.includes(step.rval) === target; break; + case 're': outcome = step.rval.test(`${v}`); break; default: outcome = hasOwn === target; break; } if ( outcome ) { return k; } @@ -13632,7 +13882,7 @@ class JSONPath { continue; } if ( c0 === 0x27 /* ' */ ) { - const r = this.#consumeQuotedIdentifier(query, i+1); + const r = this.#untilChar(query, 0x27 /* ' */, i+1) if ( r === undefined ) { return; } keys.push(r.s); i = r.i; @@ -13653,22 +13903,27 @@ class JSONPath { } return { s: keys.length === 1 ? keys[0] : keys, i }; } - #consumeQuotedIdentifier(query, i) { + #consumeUnquotedIdentifier(query, i) { + const match = this.#reUnquotedIdentifier.exec(query.slice(i)); + if ( match === null ) { return; } + return match[0]; + } + #untilChar(query, targetCharCode, i) { const len = query.length; const parts = []; let beg = i, end = i; for (;;) { if ( end === len ) { return; } const c = query.charCodeAt(end); - if ( c === 0x27 /* ' */ ) { + if ( c === targetCharCode ) { parts.push(query.slice(beg, end)); end += 1; break; } if ( c === 0x5C /* \ */ && (end+1) < len ) { parts.push(query.slice(beg, end)); - const d = query.chatCodeAt(end+1); - if ( d === 0x27 || d === 0x5C ) { + const d = query.charCodeAt(end+1); + if ( d === targetCharCode || d === 0x5C ) { end += 1; beg = end; } @@ -13677,12 +13932,20 @@ class JSONPath { } return { s: parts.join(''), i: end }; } - #consumeUnquotedIdentifier(query, i) { - const match = this.#reUnquotedIdentifier.exec(query.slice(i)); - if ( match === null ) { return; } - return match[0]; - } #compileExpr(query, step, i) { + if ( query.startsWith('=/', i) ) { + const r = this.#untilChar(query, 0x2F /* / */, i+2); + if ( r === undefined ) { return i; } + const match = /^[i]/.exec(query.slice(r.i)); + try { + step.rval = new RegExp(r.s, match && match[0] || undefined); + } catch { + return i; + } + step.op = 're'; + if ( match ) { r.i += match[0].length; } + return r.i; + } const match = this.#reExpr.exec(query.slice(i)); if ( match === null ) { return i; } try { @@ -13722,6 +13985,7 @@ class JSONPath { case '^=': outcome = `${v}`.startsWith(step.rval) === target; break; case '$=': outcome = `${v}`.endsWith(step.rval) === target; break; case '*=': outcome = `${v}`.includes(step.rval) === target; break; + case 're': outcome = step.rval.test(`${v}`); break; default: outcome = hasOwn === target; break; } if ( outcome ) { return k; } @@ -13896,6 +14160,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -13908,7 +14176,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -14467,7 +14735,7 @@ class JSONPath { continue; } if ( c0 === 0x27 /* ' */ ) { - const r = this.#consumeQuotedIdentifier(query, i+1); + const r = this.#untilChar(query, 0x27 /* ' */, i+1) if ( r === undefined ) { return; } keys.push(r.s); i = r.i; @@ -14488,22 +14756,27 @@ class JSONPath { } return { s: keys.length === 1 ? keys[0] : keys, i }; } - #consumeQuotedIdentifier(query, i) { + #consumeUnquotedIdentifier(query, i) { + const match = this.#reUnquotedIdentifier.exec(query.slice(i)); + if ( match === null ) { return; } + return match[0]; + } + #untilChar(query, targetCharCode, i) { const len = query.length; const parts = []; let beg = i, end = i; for (;;) { if ( end === len ) { return; } const c = query.charCodeAt(end); - if ( c === 0x27 /* ' */ ) { + if ( c === targetCharCode ) { parts.push(query.slice(beg, end)); end += 1; break; } if ( c === 0x5C /* \ */ && (end+1) < len ) { parts.push(query.slice(beg, end)); - const d = query.chatCodeAt(end+1); - if ( d === 0x27 || d === 0x5C ) { + const d = query.charCodeAt(end+1); + if ( d === targetCharCode || d === 0x5C ) { end += 1; beg = end; } @@ -14512,12 +14785,20 @@ class JSONPath { } return { s: parts.join(''), i: end }; } - #consumeUnquotedIdentifier(query, i) { - const match = this.#reUnquotedIdentifier.exec(query.slice(i)); - if ( match === null ) { return; } - return match[0]; - } #compileExpr(query, step, i) { + if ( query.startsWith('=/', i) ) { + const r = this.#untilChar(query, 0x2F /* / */, i+2); + if ( r === undefined ) { return i; } + const match = /^[i]/.exec(query.slice(r.i)); + try { + step.rval = new RegExp(r.s, match && match[0] || undefined); + } catch { + return i; + } + step.op = 're'; + if ( match ) { r.i += match[0].length; } + return r.i; + } const match = this.#reExpr.exec(query.slice(i)); if ( match === null ) { return i; } try { @@ -14557,6 +14838,7 @@ class JSONPath { case '^=': outcome = `${v}`.startsWith(step.rval) === target; break; case '$=': outcome = `${v}`.endsWith(step.rval) === target; break; case '*=': outcome = `${v}`.includes(step.rval) === target; break; + case 're': outcome = step.rval.test(`${v}`); break; default: outcome = hasOwn === target; break; } if ( outcome ) { return k; } @@ -14739,6 +15021,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -14751,7 +15037,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -15310,7 +15596,7 @@ class JSONPath { continue; } if ( c0 === 0x27 /* ' */ ) { - const r = this.#consumeQuotedIdentifier(query, i+1); + const r = this.#untilChar(query, 0x27 /* ' */, i+1) if ( r === undefined ) { return; } keys.push(r.s); i = r.i; @@ -15331,22 +15617,27 @@ class JSONPath { } return { s: keys.length === 1 ? keys[0] : keys, i }; } - #consumeQuotedIdentifier(query, i) { + #consumeUnquotedIdentifier(query, i) { + const match = this.#reUnquotedIdentifier.exec(query.slice(i)); + if ( match === null ) { return; } + return match[0]; + } + #untilChar(query, targetCharCode, i) { const len = query.length; const parts = []; let beg = i, end = i; for (;;) { if ( end === len ) { return; } const c = query.charCodeAt(end); - if ( c === 0x27 /* ' */ ) { + if ( c === targetCharCode ) { parts.push(query.slice(beg, end)); end += 1; break; } if ( c === 0x5C /* \ */ && (end+1) < len ) { parts.push(query.slice(beg, end)); - const d = query.chatCodeAt(end+1); - if ( d === 0x27 || d === 0x5C ) { + const d = query.charCodeAt(end+1); + if ( d === targetCharCode || d === 0x5C ) { end += 1; beg = end; } @@ -15355,12 +15646,20 @@ class JSONPath { } return { s: parts.join(''), i: end }; } - #consumeUnquotedIdentifier(query, i) { - const match = this.#reUnquotedIdentifier.exec(query.slice(i)); - if ( match === null ) { return; } - return match[0]; - } #compileExpr(query, step, i) { + if ( query.startsWith('=/', i) ) { + const r = this.#untilChar(query, 0x2F /* / */, i+2); + if ( r === undefined ) { return i; } + const match = /^[i]/.exec(query.slice(r.i)); + try { + step.rval = new RegExp(r.s, match && match[0] || undefined); + } catch { + return i; + } + step.op = 're'; + if ( match ) { r.i += match[0].length; } + return r.i; + } const match = this.#reExpr.exec(query.slice(i)); if ( match === null ) { return i; } try { @@ -15400,6 +15699,7 @@ class JSONPath { case '^=': outcome = `${v}`.startsWith(step.rval) === target; break; case '$=': outcome = `${v}`.endsWith(step.rval) === target; break; case '*=': outcome = `${v}`.includes(step.rval) === target; break; + case 're': outcome = step.rval.test(`${v}`); break; default: outcome = hasOwn === target; break; } if ( outcome ) { return k; } @@ -16325,6 +16625,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -16337,7 +16641,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -18144,6 +18448,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -18156,7 +18464,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -18789,6 +19097,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -18801,7 +19113,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -18899,6 +19211,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -18911,7 +19227,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -19350,6 +19666,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -19362,7 +19682,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -20254,6 +20574,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -20266,7 +20590,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -20589,6 +20913,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -20601,7 +20929,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -20894,6 +21222,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -20906,7 +21238,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -22109,6 +22441,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -22121,7 +22457,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -22252,10 +22588,19 @@ function trustedReplaceArgument( const logPrefix = safe.makeLogPrefix('trusted-replace-argument', propChain, argposRaw, argraw); const argoffset = parseInt(argposRaw, 10) || 0; const extraArgs = safe.getExtraArgs(Array.from(arguments), 3); - const replacer = argraw.startsWith('repl:/') && - parseReplaceFn(argraw.slice(5)) || undefined; - const value = replacer === undefined && - validateConstantFn(true, argraw, extraArgs); + let replacer; + if ( argraw.startsWith('repl:/') ) { + const parsed = parseReplaceFn(argraw.slice(5)); + if ( parsed === undefined ) { return; } + replacer = arg => `${arg}`.replace(replacer.re, replacer.replacement); + } else if ( argraw.startsWith('add:') ) { + const delta = parseFloat(argraw.slice(4)); + if ( isNaN(delta) ) { return; } + replacer = arg => Number(arg) + delta; + } else { + const value = validateConstantFn(true, argraw, extraArgs); + replacer = ( ) => value; + } const reCondition = extraArgs.condition ? safe.patternToRegex(extraArgs.condition) : /^/; @@ -22287,9 +22632,7 @@ function trustedReplaceArgument( return context.reflect(); } } - const argAfter = replacer && typeof argBefore === 'string' - ? argBefore.replace(replacer.re, replacer.replacement) - : value; + const argAfter = replacer(argBefore); if ( argAfter !== argBefore ) { setArg(context, argAfter); safe.uboLog(logPrefix, `Replaced argument:\nBefore: ${JSON.stringify(argBefore)}\nAfter: ${argAfter}`); @@ -26500,6 +26843,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -26512,7 +26859,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -28553,6 +28900,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -28565,7 +28916,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -32167,6 +32518,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -32179,7 +32534,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -32298,6 +32653,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -32310,7 +32669,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -33367,6 +33726,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -33379,7 +33742,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); }; @@ -33737,6 +34100,10 @@ function proxyApplyFn( : new proxyApplyFn.ApplyContext(...args); } }; + proxyApplyFn.isCtor = new Map(); + } + if ( proxyApplyFn.isCtor.has(target) === false ) { + proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn); } const fnStr = fn.toString(); const toString = (function toString() { return fnStr; }).bind(null); @@ -33749,7 +34116,7 @@ function proxyApplyFn( return Reflect.get(target, prop); }, }; - if ( fn.prototype?.constructor === fn ) { + if ( proxyApplyFn.isCtor.get(target) ) { proxyDetails.construct = function(target, args) { return handler(proxyApplyFn.CtorContext.factory(target, args)); };