kn-es-features 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esfeatures.iife.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var EsFeatures=function(exports){"use strict";var _documentCurrentScript=typeof document<"u"?document.currentScript:null;function _arrayLikeToArray(a,t){(t==null||t>a.length)&&(t=a.length);for(var e=0,
|
|
2
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var r,s=!0,o=!1;return{s:function(){e=e.call(a)},n:function(){var
|
|
1
|
+
var EsFeatures=function(exports){"use strict";var _documentCurrentScript=typeof document<"u"?document.currentScript:null;function _arrayLikeToArray(a,t){(t==null||t>a.length)&&(t=a.length);for(var e=0,i=Array(t);e<t;e++)i[e]=a[e];return i}function _arrayWithHoles(a){if(Array.isArray(a))return a}function _arrayWithoutHoles(a){if(Array.isArray(a))return _arrayLikeToArray(a)}function _assertClassBrand(a,t,e){if(typeof a=="function"?a===t:a.has(t))return arguments.length<3?t:e;throw new TypeError("Private element is not present on this object")}function _assertThisInitialized(a){if(a===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function asyncGeneratorStep(a,t,e,i,n,r,s){try{var o=a[r](s),u=o.value}catch(c){return void e(c)}o.done?t(u):Promise.resolve(u).then(i,n)}function _asyncToGenerator(a){return function(){var t=this,e=arguments;return new Promise(function(i,n){var r=a.apply(t,e);function s(u){asyncGeneratorStep(r,i,n,s,o,"next",u)}function o(u){asyncGeneratorStep(r,i,n,s,o,"throw",u)}s(void 0)})}}function _callSuper(a,t,e){return t=_getPrototypeOf(t),_possibleConstructorReturn(a,_isNativeReflectConstruct()?Reflect.construct(t,e||[],_getPrototypeOf(a).constructor):t.apply(a,e))}function _checkInRHS(a){if(Object(a)!==a)throw TypeError("right-hand side of 'in' should be an object, got "+(a!==null?typeof a:"null"));return a}function _checkPrivateRedeclaration(a,t){if(t.has(a))throw new TypeError("Cannot initialize the same private elements twice on an object")}function _classCallCheck(a,t){if(!(a instanceof t))throw new TypeError("Cannot call a class as a function")}function _classPrivateFieldGet2(a,t){return a.get(_assertClassBrand(a,t))}function _classPrivateFieldInitSpec(a,t,e){_checkPrivateRedeclaration(a,t),t.set(a,e)}function _classPrivateFieldSet2(a,t,e){return a.set(_assertClassBrand(a,t),e),e}function _classPrivateMethodInitSpec(a,t){_checkPrivateRedeclaration(a,t),t.add(a)}function _construct(a,t,e){if(_isNativeReflectConstruct())return Reflect.construct.apply(null,arguments);var i=[null];i.push.apply(i,t);var n=new(a.bind.apply(a,i));return e&&_setPrototypeOf(n,e.prototype),n}function _defineProperties(a,t){for(var e=0;e<t.length;e++){var i=t[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(a,_toPropertyKey(i.key),i)}}function _createClass(a,t,e){return t&&_defineProperties(a.prototype,t),e&&_defineProperties(a,e),Object.defineProperty(a,"prototype",{writable:!1}),a}function _createForOfIteratorHelper(a,t){var e=typeof Symbol<"u"&&a[Symbol.iterator]||a["@@iterator"];if(!e){if(Array.isArray(a)||(e=_unsupportedIterableToArray(a))||t&&a&&typeof a.length=="number"){e&&(a=e);var i=0,n=function(){};return{s:n,n:function(){return i>=a.length?{done:!0}:{done:!1,value:a[i++]}},e:function(u){throw u},f:n}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
2
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var r,s=!0,o=!1;return{s:function(){e=e.call(a)},n:function(){var u=e.next();return s=u.done,u},e:function(u){o=!0,r=u},f:function(){try{s||e.return==null||e.return()}finally{if(o)throw r}}}}function _defineProperty(a,t,e){return(t=_toPropertyKey(t))in a?Object.defineProperty(a,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):a[t]=e,a}function _get(){return _get=typeof Reflect<"u"&&Reflect.get?Reflect.get.bind():function(a,t,e){var i=_superPropBase(a,t);if(i){var n=Object.getOwnPropertyDescriptor(i,t);return n.get?n.get.call(arguments.length<3?a:e):n.value}},_get.apply(null,arguments)}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},_getPrototypeOf(a)}function _inherits(a,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(t&&t.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),Object.defineProperty(a,"prototype",{writable:!1}),t&&_setPrototypeOf(a,t)}function _isNativeFunction(a){try{return Function.toString.call(a).indexOf("[native code]")!==-1}catch{return typeof a=="function"}}function _isNativeReflectConstruct(){try{var a=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(_isNativeReflectConstruct=function(){return!!a})()}function _iterableToArray(a){if(typeof Symbol<"u"&&a[Symbol.iterator]!=null||a["@@iterator"]!=null)return Array.from(a)}function _iterableToArrayLimit(a,t){var e=a==null?null:typeof Symbol<"u"&&a[Symbol.iterator]||a["@@iterator"];if(e!=null){var i,n,r,s,o=[],u=!0,c=!1;try{if(r=(e=e.call(a)).next,t===0){if(Object(e)!==e)return;u=!1}else for(;!(u=(i=r.call(e)).done)&&(o.push(i.value),o.length!==t);u=!0);}catch(f){c=!0,n=f}finally{try{if(!u&&e.return!=null&&(s=e.return(),Object(s)!==s))return}finally{if(c)throw n}}return o}}function _nonIterableRest(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
3
3
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function _nonIterableSpread(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
4
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ownKeys(a,t){var e=Object.keys(a);if(Object.getOwnPropertySymbols){var
|
|
5
|
-
共 `.concat(a.length," 项,通过 ").concat(t,",失败 ").concat(e))}function testLetConst(){var a=createSuite("let & const"),t=a.test,e=a.assert,u=a.getResults;return t("let 块级作用域",function(){for(var n=[],r=0;r<3;r++)n.push(r);e(n[0]===0&&n[2]===2,"let 循环变量应为独立值")}),t("const 声明常量",function(){var n=3.14159;e(n===3.14159,"const 值应保持不变")}),u()}function testArrowFunctions(){var a=createSuite("箭头函数"),t=a.test,e=a.assert,u=a.getResults;return t("基本语法",function(){var n=function(s,o){return s+o};e(n(2,3)===5,"箭头函数返回值应为 5")}),u()}function testTemplateLiterals(){var a=createSuite("模板字符串"),t=a.test,e=a.assert,u=a.getResults;return t("基本插值",function(){var n="ES2015",r="Hello, ".concat(n,"!");e(r==="Hello, ES2015!","模板字符串插值应正确")}),u()}function testDestructuring(){var a=createSuite("解构赋值"),t=a.test,e=a.assert,u=a.getResults;return t("数组解构 - 基本",function(){var n=3;e(n===3,"数组解构基本用法")}),t("数组解构 - 跳过元素",function(){var n=[1,2,3,4],r=n[3];e(r===4,"数组解构可跳过元素")}),u()}function testDefaultRestSpread(){var a=createSuite("默认参数/Rest/Spread"),t=a.test,e=a.assert,u=a.getResults;return t("spread 对象覆盖属性",function(){var n={a:1,b:2},r=_objectSpread2(_objectSpread2({},n),{},{b:99});e(r.b===99,"spread 后面属性覆盖前面")}),u()}function testClasses(){var a=createSuite("类(Class)"),t=a.test,e=a.assert,u=a.getResults;return t("基本类定义",function(){var n=function(){function s(o){_classCallCheck(this,s),this.name=o}return _createClass(s,[{key:"speak",value:function(){return"".concat(this.name," makes a sound.")}}])}(),r=new n("Cat");e(r.name==="Cat","构造函数应正确赋值"),e(r.speak()==="Cat makes a sound.","实例方法应正常工作")}),t("类继承",function(){var n=function(){function o(i){_classCallCheck(this,o),this.name=i}return _createClass(o,[{key:"speak",value:function(){return"".concat(this.name,": ...")}}])}(),r=function(o){function i(){return _classCallCheck(this,i),_callSuper(this,i,arguments)}return _inherits(i,o),_createClass(i,[{key:"speak",value:function(){return"".concat(this.name,": Woof!")}}])}(n),s=new r("Rex");e(s.speak()==="Rex: Woof!","子类应覆盖父类方法"),e(s instanceof r&&s instanceof n,"instanceof 检查应通过")}),t("super 调用父类方法",function(){var n=function(){function o(){_classCallCheck(this,o)}return _createClass(o,[{key:"area",value:function(){return 0}},{key:"describe",value:function(){return"面积: ".concat(this.area())}}])}(),r=function(o){function i(c){var f;return _classCallCheck(this,i),f=_callSuper(this,i),f.r=c,f}return _inherits(i,o),_createClass(i,[{key:"area",value:function(){return Math.PI*this.r*this.r}},{key:"describe",value:function(){return _superPropGet(i,"describe",this,3)([])+" (圆形)"}}])}(n),s=new r(1);e(s.describe().includes("面积:"),"super 方法调用")}),t("静态方法",function(){var n=function(){function r(){_classCallCheck(this,r)}return _createClass(r,null,[{key:"add",value:function(o,i){return o+i}}])}();_defineProperty(n,"PI",3.14159),e(n.add(2,3)===5,"静态方法应直接通过类调用"),e(n.PI===3.14159,"静态属性应正确设置")}),t("getter 和 setter",function(){var n=function(){function s(o){_classCallCheck(this,s),this._celsius=o}return _createClass(s,[{key:"fahrenheit",get:function(){return this._celsius*9/5+32},set:function(i){this._celsius=(i-32)*5/9}}])}(),r=new n(0);e(r.fahrenheit===32,"getter 应正确计算"),r.fahrenheit=212,e(Math.round(r._celsius)===100,"setter 应正确转换")}),t("私有字段 (#)",function(){var n=new WeakMap,r=function(){function o(){_classCallCheck(this,o),_classPrivateFieldInitSpec(this,n,0)}return _createClass(o,[{key:"increment",value:function(){var c;_classPrivateFieldSet2(n,this,(c=_classPrivateFieldGet2(n,this),c++,c))}},{key:"value",get:function(){return _classPrivateFieldGet2(n,this)}}])}(),s=new r;s.increment(),s.increment(),e(s.value===2,"私有字段应正确工作"),e(!("count"in s),"私有字段不可从外部访问")}),t("类表达式",function(){var n=function(){function s(o,i){_classCallCheck(this,s),this.w=o,this.h=i}return _createClass(s,[{key:"area",value:function(){return this.w*this.h}}])}(),r=new n(3,4);e(r.area()===12,"类表达式应正常工作")}),t("类不存在变量提升",function(){try{new Function('"use strict"; new Foo(); class Foo {}')(),e(!1,"应抛出 ReferenceError")}catch{e(!0,"类不提升,使用前必须先声明")}}),u()}function testPromises(){return _testPromises.apply(this,arguments)}function _testPromises(){return _testPromises=_asyncToGenerator(_regenerator().m(function a(){var t,e,u,n,r;return _regenerator().w(function(s){for(;;)switch(s.n){case 0:return t=createSuite("Promise"),e=t.test,u=t.assert,n=t.getResults,r=[],r.push(e("基本 Promise resolve",function(){return new Promise(function(o){return o(42)}).then(function(o){return u(o===42,"resolve 值应为 42")})})),r.push(e("基本 Promise reject",function(){return new Promise(function(o,i){return i(new Error("失败"))}).catch(function(o){return u(o.message==="失败","reject 应携带错误信息")})})),r.push(e("Promise 链式调用",function(){return Promise.resolve(1).then(function(o){return o+1}).then(function(o){return o*3}).then(function(o){return u(o===6,"链式调用结果应为 6")})})),r.push(e("Promise.all - 全部成功",function(){return Promise.all([Promise.resolve(1),Promise.resolve(2),Promise.resolve(3)]).then(function(o){return u(o.join(",")==="1,2,3","Promise.all 应返回所有结果")})})),r.push(e("Promise.all - 一个失败则全部失败",function(){return Promise.all([Promise.resolve(1),Promise.reject(new Error("error")),Promise.resolve(3)]).catch(function(o){return u(o.message==="error","Promise.all 中有失败应 reject")})})),r.push(e("Promise.race - 返回最快的结果",function(){var o=new Promise(function(c){return setTimeout(function(){return c("slow")},100)}),i=Promise.resolve("fast");return Promise.race([o,i]).then(function(c){return u(c==="fast","Promise.race 应返回最快完成的")})})),r.push(e("Promise.allSettled - 全部结果",function(){return Promise.allSettled([Promise.resolve(1),Promise.reject("err")]).then(function(o){u(o[0].status==="fulfilled","allSettled fulfilled"),u(o[1].status==="rejected","allSettled rejected")})})),r.push(e("Promise.any - 返回第一个成功",function(){return Promise.any([Promise.reject("e1"),Promise.resolve("ok"),Promise.resolve("ok2")]).then(function(o){return u(o==="ok","Promise.any 应返回第一个成功的值")})})),r.push(e("async/await 基本用法",_asyncToGenerator(_regenerator().m(function o(){var i,c,f;return _regenerator().w(function(l){for(;;)switch(l.n){case 0:return c=function(){return c=_asyncToGenerator(_regenerator().m(function y(){var p;return _regenerator().w(function(S){for(;;)switch(S.n){case 0:return S.n=1,Promise.resolve("data");case 1:return p=S.v,S.a(2,p)}},y)})),c.apply(this,arguments)},i=function(){return c.apply(this,arguments)},l.n=1,i();case 1:f=l.v,u(f==="data","async/await 应正确获取异步结果");case 2:return l.a(2)}},o)})))),r.push(e("async/await 错误处理",_asyncToGenerator(_regenerator().m(function o(){var i,c,f;return _regenerator().w(function(l){for(;;)switch(l.p=l.n){case 0:return c=function(){return c=_asyncToGenerator(_regenerator().m(function y(){return _regenerator().w(function(p){for(;;)switch(p.n){case 0:throw new Error("async error");case 1:return p.a(2)}},y)})),c.apply(this,arguments)},i=function(){return c.apply(this,arguments)},l.p=1,l.n=2,i();case 2:u(!1,"应抛出错误"),l.n=4;break;case 3:l.p=3,f=l.v,u(f.message==="async error","async/await 错误处理");case 4:return l.a(2)}},o,null,[[1,3]])})))),s.n=1,Promise.all(r.filter(Boolean));case 1:return s.a(2,n())}},a)})),_testPromises.apply(this,arguments)}function testSymbols(){var a=createSuite("Symbol"),t=a.test,e=a.assert,u=a.getResults;return t("Symbol 唯一性",function(){var n=Symbol("desc"),r=Symbol("desc");e(n!==r,"相同描述的 Symbol 不相等")}),u()}function testIteratorsGenerators(){var a=createSuite("迭代器与生成器"),t=a.test,e=a.assert,u=a.getResults;return t("自定义迭代器",function(){function n(s){var o=0;return{next:function(){return o<s.length?{value:s[o++],done:!1}:{value:void 0,done:!0}}}}var r=n([1,2,3]);e(r.next().value===1,"第一次 next 返回 1"),e(r.next().value===2,"第二次 next 返回 2"),e(r.next().done===!1,"第三次未完成"),e(r.next().done===!0,"第四次完成")}),t("可迭代对象 for...of",function(){for(var n=[],r=0,s=[10,20,30];r<s.length;r++){var o=s[r];n.push(o)}e(n.join(",")==="10,20,30","for...of 迭代数组")}),u()}function testMapSet(){var a=createSuite("Map & Set"),t=a.test,e=a.assert,u=a.getResults;return t("Map 基本操作",function(){var n=new Map;n.set("a",1),n.set("b",2),e(n.get("a")===1,"Map.get 应返回正确值"),e(n.has("b")===!0,"Map.has 应返回 true"),e(n.size===2,"Map.size 应为 2"),n.delete("a"),e(n.size===1,"删除后 size 应为 1")}),u()}function testProxyReflect(){var a=createSuite("Proxy & Reflect"),t=a.test,e=a.assert,u=a.getResults;return t("Proxy get 拦截",function(){var n={get:function(o,i){return i in o?o[i]:'属性 "'.concat(i,'" 不存在')}},r=new Proxy({name:"Alice"},n);e(r.name==="Alice","Proxy get 已有属性"),e(r.age==='属性 "age" 不存在',"Proxy get 不存在属性")}),t("Proxy set 拦截与验证",function(){var n={set:function(o,i,c){if(typeof c!="number")throw new TypeError("只允许数字");return o[i]=c,!0}},r=new Proxy({},n);r.score=90,e(r.score===90,"Proxy set 数字");try{r.score="hello",e(!1,"应抛出 TypeError")}catch(s){e(s instanceof TypeError,"Proxy set 类型校验")}}),u()}function testEnhancedObjects(){var a=createSuite("增强对象字面量"),t=a.test,e=a.assert,u=a.getResults;return t("属性简写",function(){var n="Alice",r=25,s={name:n,age:r};e(s.age===25,"属性简写")}),t("方法简写",function(){var n={greet:function(s){return"Hello, ".concat(s,"!")}};e(n.greet("Bob")==="Hello, Bob!","方法简写")}),u()}function testNewMethods(){var a=createSuite("新增内置方法"),t=a.test,e=a.assert,u=a.getResults;return t("Array.from 类数组转换",function(){var n=Array.from("hello");e(n.join(",")==="h,e,l,l,o","Array.from 字符串");var r=Array.from([1,2,3],function(s){return s*2});e(r.join(",")==="2,4,6","Array.from 带映射函数")}),t("Array.of 创建数组",function(){var n=Array.of(1,2,3);e(n.length===3&&n[0]===1,"Array.of 创建数组"),e(Array.of(7).length===1,"Array.of(7) 和 new Array(7) 不同")}),t("Array.prototype.find / findIndex",function(){var n=[1,2,3,4,5];e(n.find(function(r){return r>3})===4,"find 返回第一个满足条件的元素"),e(n.findIndex(function(r){return r>3})===3,"findIndex 返回第一个满足条件的索引"),e(n.find(function(r){return r>10})===void 0,"find 无匹配返回 undefined")}),t("Array.prototype.fill",function(){var n=[1,2,3,4,5];n.fill(0,2,4),e(n.join(",")==="1,2,0,0,5","fill 局部填充")}),t("Array.prototype.includes",function(){e([1,2,3].includes(2),"includes 存在的元素"),e(![1,2,3].includes(4),"includes 不存在的元素"),e([1,NaN].includes(NaN),"includes 可检测 NaN(indexOf 不行)")}),t("Array.prototype.flat / flatMap",function(){var n=[1,[2,[3,[4]]]];e(n.flat().join(",")==="1,2,3,4","flat 一层"),e(n.flat(1/0).join(",")==="1,2,3,4","flat Infinity 层");var r=[1,2,3].flatMap(function(s){return[s,s*2]});e(r.join(",")==="1,2,2,4,3,6","flatMap")}),t("String.prototype.includes / startsWith / endsWith",function(){var n="Hello, World!";e(n.includes("World"),"includes"),e(n.startsWith("Hello"),"startsWith"),e(n.endsWith("!"),"endsWith"),e(n.startsWith("World",7),"startsWith 从指定位置")}),t("String.prototype.repeat",function(){e("ha".repeat(3)==="hahaha","repeat"),e("".repeat(5)==="","空字符串 repeat")}),t("String.prototype.padStart / padEnd",function(){e("5".padStart(3,"0")==="005","padStart"),e("hi".padEnd(5,".")==="hi...","padEnd"),e("hello".padStart(3)==="hello","长度不足不截断")}),t("String.prototype.trimStart / trimEnd",function(){e(" hello ".trimStart()==="hello ","trimStart"),e(" hello ".trimEnd()===" hello","trimEnd")}),t("Number.isInteger",function(){e(Number.isInteger(42),"42 是整数"),e(!Number.isInteger(42.5),"42.5 不是整数"),e(!Number.isInteger("42"),"字符串不是整数")}),t("Number.isFinite / isNaN",function(){e(Number.isFinite(42),"42 是有限数"),e(!Number.isFinite(1/0),"Infinity 不是有限数"),e(Number.isNaN(NaN),"NaN 是 NaN"),e(!Number.isNaN(42),"42 不是 NaN"),e(!Number.isNaN("NaN"),"字符串 NaN 不触发(与全局 isNaN 不同)")}),t("Number.parseInt / parseFloat",function(){e(Number.parseInt("42px")===42,"Number.parseInt"),e(Number.parseFloat("3.14abc")===3.14,"Number.parseFloat")}),t("Number.EPSILON",function(){var n=.30000000000000004;e(Math.abs(n-.3)<Number.EPSILON,"Number.EPSILON 用于浮点比较")}),t("Number.MAX_SAFE_INTEGER / MIN_SAFE_INTEGER",function(){e(Number.MAX_SAFE_INTEGER===Math.pow(2,53)-1,"MAX_SAFE_INTEGER"),e(Number.isSafeInteger(Number.MAX_SAFE_INTEGER),"isSafeInteger"),e(!Number.isSafeInteger(Number.MAX_SAFE_INTEGER+1),"超出安全整数范围")}),t("Math.sign",function(){e(Math.sign(-5)===-1,"Math.sign 负数"),e(Math.sign(0)===0,"Math.sign 零"),e(Math.sign(5)===1,"Math.sign 正数")}),t("Math.trunc",function(){e(Math.trunc(3.9)===3,"Math.trunc 正数"),e(Math.trunc(-3.9)===-3,"Math.trunc 负数")}),t("Math.cbrt / Math.hypot / Math.log2 / Math.log10",function(){e(Math.cbrt(27)===3,"Math.cbrt 立方根"),e(Math.hypot(3,4)===5,"Math.hypot 斜边"),e(Math.log2(8)===3,"Math.log2"),e(Math.log10(1e3)===3,"Math.log10")}),u()}const _13NewMethods=Object.freeze(Object.defineProperty({__proto__:null,testNewMethods},Symbol.toStringTag,{value:"Module"}));function testModules(){var a=createSuite("模块(Modules)"),t=a.test,e=a.assert,u=a.getResults;return t("命名导出与导入(本工程已在使用)",function(){e(typeof testModules=="function","命名导出的函数可正常被导入调用")}),t("模块作用域独立",function(){var n=new Function("return this")();e(n!==void 0||!0,"模块顶层有独立作用域")}),t("import.meta 可用",function(){e(_typeof({url:_documentCurrentScript&&_documentCurrentScript.tagName.toUpperCase()==="SCRIPT"&&_documentCurrentScript.src||new URL("esfeatures.iife.js",document.baseURI).href})==="object","import.meta 是对象")}),t("动态 import() 返回 Promise",_asyncToGenerator(_regenerator().m(function n(){var r,s;return _regenerator().w(function(o){for(;;)switch(o.n){case 0:return r=Promise.resolve().then(()=>_13NewMethods),e(r instanceof Promise,"动态 import() 返回 Promise"),o.n=1,r;case 1:s=o.v,e(typeof s.testNewMethods=="function","动态导入的模块可正常使用");case 2:return o.a(2)}},n)}))),t("export default 默认导出",function(){e(!0,'默认导出通过 import x from "..." 引入,本工程采用命名导出模式')}),u()}function testBinaryOctalUnicode(){var a=createSuite("进制字面量与Unicode"),t=a.test,e=a.assert,u=a.getResults;return t("二进制字面量 0b",function(){var n=10;e(n===10,"0b1010 应等于十进制 10"),e(!0,"0b11111111 应等于 255")}),t("八进制字面量 0o",function(){var n=15;e(n===15,"0o17 应等于十进制 15"),e(!0,"0o777 应等于 511")}),t("十六进制字面量 0x",function(){e(!0,"0xFF 应等于 255"),e(!0,"0x10 应等于 16")}),t("Number.prototype.toString 进制转换",function(){e(255 .toString(16)==="ff","255 转十六进制"),e(10 .toString(2)==="1010","10 转二进制"),e(15 .toString(8)==="17","15 转八进制")}),t("Unicode 转义 \\uXXXX",function(){var n="♥";e(n==="♥","\\u2665 应为心形符号")}),t("Unicode 码点转义 \\u{XXXXX}",function(){var n="😀";e(n.length===2,"Unicode 超过 FFFF 的字符长度为 2"),e(n.codePointAt(0)===128512,"codePointAt 返回正确码点")}),t("String.fromCodePoint",function(){var n=String.fromCodePoint(128512);e(n.codePointAt(0)===128512,"String.fromCodePoint 与 codePointAt 对应")}),t("字符串 normalize 方法",function(){var n="é",r="é";e(n!==r,"组合与分解形式不直接相等"),e(n===r.normalize("NFC"),"normalize NFC 后相等")}),t("for...of 正确迭代 Unicode 字符",function(){var n="😀A",r=_toConsumableArray(n);e(r.length===2,"for...of 正确按码点迭代")}),u()}function testForOf(){var a=createSuite("for...of 与迭代协议"),t=a.test,e=a.assert,u=a.getResults;return t("for...of 迭代数组",function(){for(var n=[],r=0,s=[1,2,3];r<s.length;r++){var o=s[r];n.push(o)}e(n.join(",")==="1,2,3","for...of 迭代数组")}),t("for...of 迭代字符串",function(){var n=[],r=_createForOfIteratorHelper("abc"),s;try{for(r.s();!(s=r.n()).done;){var o=s.value;n.push(o)}}catch(i){r.e(i)}finally{r.f()}e(n.join("")==="abc","for...of 迭代字符串")}),t("for...of 迭代 Set",function(){var n=[],r=_createForOfIteratorHelper(new Set([1,2,3])),s;try{for(r.s();!(s=r.n()).done;){var o=s.value;n.push(o)}}catch(i){r.e(i)}finally{r.f()}e(n.join(",")==="1,2,3","for...of 迭代 Set")}),t("for...of 迭代 Map",function(){var n=[],r=_createForOfIteratorHelper(new Map([["a",1],["b",2]])),s;try{for(r.s();!(s=r.n()).done;){var o=_slicedToArray(s.value,2),i=o[0],c=o[1];n.push("".concat(i,"=").concat(c))}}catch(f){r.e(f)}finally{r.f()}e(n.join(",")==="a=1,b=2","for...of 迭代 Map")}),t("for...of 迭代 arguments",function(){function n(){var r=[],s=_createForOfIteratorHelper(arguments),o;try{for(s.s();!(o=s.n()).done;){var i=o.value;r.push(i)}}catch(c){s.e(c)}finally{s.f()}return r}e(n(1,2,3).join(",")==="1,2,3","for...of 迭代 arguments")}),u()}function testMapGetOrInsert(){var a=createSuite("map getOrInsert"),t=a.test,e=a.assert,u=a.getResults;return t("getOrInsert - key 已存在返回原值",function(){var n=new Map([["bar","foo"]]),r=n.getOrInsert("bar","default");e(r==="foo","key 已存在应返回原值 foo")}),u()}function testClassFields(){var _createSuite=createSuite("Class Fields (ES2022)"),test=_createSuite.test,assert=_createSuite.assert,getResults=_createSuite.getResults;return test("公共实例字段 —— 声明并初始化",function(){var a=_createClass(function e(u,n){_classCallCheck(this,e),_defineProperty(this,"x",0),_defineProperty(this,"y",0),this.x=u,this.y=n}),t=new a(3,4);assert(t.x===3&&t.y===4,"公共字段应可读写")}),test("公共字段默认值在 constructor 之前初始化",function(){var a=_createClass(function t(){_classCallCheck(this,t),_defineProperty(this,"count",10),this.count+=5});assert(new a().count===15,"默认值应先于 constructor 体初始化")}),test("私有实例字段 #field —— 外部不可访问",function(){var _balance=new WeakMap,BankAccount=function(){function a(){_classCallCheck(this,a),_classPrivateFieldInitSpec(this,_balance,0)}return _createClass(a,[{key:"deposit",value:function(e){_classPrivateFieldSet2(_balance,this,_classPrivateFieldGet2(_balance,this)+e)}},{key:"balance",get:function(){return _classPrivateFieldGet2(_balance,this)}}])}(),acc=new BankAccount;acc.deposit(100),assert(acc.balance===100,"私有字段应通过访问器正确读取"),assert(!("#balance"in acc),"私有字段不应出现在普通属性枚举中");var threw=!1;try{eval("acc.#balance")}catch(a){threw=!0}assert(threw,"外部直接访问私有字段应抛出语法错误")}),test("私有实例方法 #method()",function(){var a=new WeakMap,t=new WeakSet,e=function(){function n(){_classCallCheck(this,n),_classPrivateMethodInitSpec(this,t),_classPrivateFieldInitSpec(this,a,"[LOG]")}return _createClass(n,[{key:"format",value:function(s){return _assertClassBrand(t,this,u).call(this,s)}}])}();function u(n){return"".concat(_classPrivateFieldGet2(a,this)," ").concat(n)}assert(new e().format("hello")==="[LOG] hello","私有方法应正常调用")}),test("静态公共字段",function(){var a=_createClass(function t(){_classCallCheck(this,t)});_defineProperty(a,"version","1.0.0"),_defineProperty(a,"maxRetry",3),assert(a.version==="1.0.0","静态公共字段应可通过类名访问"),assert(a.maxRetry===3,"静态字段应保持初始值")}),test("静态私有字段 —— 追踪实例数量",function(){var a=function(){function e(){var u;_classCallCheck(this,e),t._=(u=t._,u++,u)}return _createClass(e,null,[{key:"getCount",value:function(){return t._}}])}(),t={_:0};new a,new a,new a,assert(a.getCount()===3,"静态私有字段应跨实例共享")}),test("静态私有方法",function(){var a=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"normalize",value:function(n){return t.call(e,n,0,1)}}])}();function t(e,u,n){return Math.min(Math.max(e,u),n)}assert(a.normalize(-.5)===0,"静态私有方法:低于下界应返回 0"),assert(a.normalize(1.5)===1,"静态私有方法:超出上界应返回 1"),assert(a.normalize(.5)===.5,"静态私有方法:正常值应原样返回")}),test("私有字段存在性:`#field in obj`",function(){var a=new WeakMap,t=function(){function e(u){_classCallCheck(this,e),_classPrivateFieldInitSpec(this,a,void 0),_classPrivateFieldSet2(a,this,u)}return _createClass(e,null,[{key:"isNode",value:function(n){return a.has(_checkInRHS(n))}}])}();assert(t.isNode(new t(1))===!0,"实例应包含私有字段"),assert(t.isNode({})===!1,"普通对象不应包含私有字段")}),test("私有字段不参与继承 —— 子类无法访问父类私有字段",function(){var a=new WeakMap,t=function(){function n(r){_classCallCheck(this,n),_classPrivateFieldInitSpec(this,a,void 0),_classPrivateFieldSet2(a,this,r)}return _createClass(n,[{key:"getName",value:function(){return _classPrivateFieldGet2(a,this)}}])}(),e=function(n){function r(){return _classCallCheck(this,r),_callSuper(this,r,arguments)}return _inherits(r,n),_createClass(r,[{key:"bark",value:function(){return"".concat(this.getName()," says woof")}}])}(t),u=new e("Rex");assert(u.bark()==="Rex says woof","子类可通过父类公共方法访问私有字段")}),getResults()}function testClassStaticBlocks(){var a=createSuite("Class Static Blocks (ES2022)"),t=a.test,e=a.assert,u=a.getResults;return t("基本静态块 —— 初始化静态字段",function(){var n,r=_createClass(function s(){_classCallCheck(this,s)});n=r,_defineProperty(r,"host",void 0),_defineProperty(r,"port",void 0),function(){n.host="localhost",n.port=8080}(),e(r.host==="localhost","静态块应初始化 host"),e(r.port===8080,"静态块应初始化 port")}),t("静态块中可使用 try/catch 处理初始化失败",function(){var n,r=_createClass(function s(){_classCallCheck(this,s)});n=r,_defineProperty(r,"value",void 0),function(){try{var s='{"timeout":3000}';n.value=JSON.parse(s).timeout}catch{n.value=1e3}}(),e(r.value===3e3,"静态块中 try/catch 初始化应正确执行")}),t("静态块访问同类私有字段",function(){var n,r=function(){function o(){_classCallCheck(this,o)}return _createClass(o,null,[{key:"getSecret",value:function(){return s._}}])}(),s={_:"initial"};n=function(i){s._=i},n("updated"),e(r.getSecret()==="updated","静态块应能操作同类私有字段")}),t("多个静态块按声明顺序执行",function(){var n,r=[],s=_createClass(function o(){_classCallCheck(this,o)});n=s,_defineProperty(s,"a",void 0),function(){r.push(1),n.a=10}(),_defineProperty(s,"b",void 0),function(){r.push(2),n.b=n.a*2}(),e(r[0]===1&&r[1]===2,"多个静态块应按顺序执行"),e(s.b===20,"第二个静态块应能读取第一个块的结果")}),t("静态块与静态字段声明交替执行",function(){var n=[],r=_createClass(function s(){_classCallCheck(this,s)});_defineProperty(r,"x",(n.push("field-x"),1)),n.push("block-1"),_defineProperty(r,"y",(n.push("field-y"),2)),n.push("block-2"),e(n.join(",")==="field-x,block-1,field-y,block-2","字段与静态块应按声明顺序交替初始化"),e(r.x===1&&r.y===2,"所有字段应正确赋值")}),t("子类静态块在父类之后执行",function(){var n=[];n.push("base"),n.push("child"),e(n[0]==="base"&&n[1]==="child","父类静态块应先于子类执行")}),t("静态块中 this 指向类本身",function(){var n,r=_createClass(function s(){_classCallCheck(this,s)});n=r,_defineProperty(r,"name2","Widget"),_defineProperty(r,"instance",void 0),n.instance={type:n.name2},e(r.instance.type==="Widget","静态块内 this 应指向类本身")}),u()}function testAtMethod(){var a=createSuite("Array/String.at() (ES2022)"),t=a.test,e=a.assert,u=a.getResults;return t("Array.at() —— 正索引与 arr[i] 等价",function(){var n=[10,20,30,40,50];e(n.at(0)===10,"at(0) 应返回第一个元素"),e(n.at(2)===30,"at(2) 应返回第三个元素"),e(n.at(4)===50,"at(4) 应返回最后一个元素")}),t("Array.at() —— 负索引从末尾倒数",function(){var n=[10,20,30,40,50];e(n.at(-1)===50,"at(-1) 应返回最后一个元素"),e(n.at(-2)===40,"at(-2) 应返回倒数第二个元素"),e(n.at(-5)===10,"at(-5) 应返回第一个元素")}),t("Array.at() —— 越界返回 undefined",function(){var n=[1,2,3];e(n.at(5)===void 0,"正向越界应返回 undefined"),e(n.at(-4)===void 0,"负向越界应返回 undefined")}),t("Array.at() —— 空数组始终返回 undefined",function(){e([].at(0)===void 0,"空数组 at(0) 应返回 undefined"),e([].at(-1)===void 0,"空数组 at(-1) 应返回 undefined")}),t("对比旧写法:arr.at(-1) vs arr[arr.length - 1]",function(){var n=[3,1,4,1,5,9,2,6],r=n.at(-1),s=n[n.length-1];e(r===s,"at(-1) 应与 arr[length-1] 等价")}),t("String.at() —— 正索引",function(){var n="hello";e(n.at(0)==="h","at(0) 应返回首字符"),e(n.at(4)==="o","at(4) 应返回末字符")}),t("String.at() —— 负索引",function(){var n="hello";e(n.at(-1)==="o","at(-1) 应返回最后一个字符"),e(n.at(-3)==="l","at(-3) 应返回倒数第三个字符")}),t("String.at() —— 越界返回 undefined",function(){e("abc".at(10)===void 0,"正向越界应返回 undefined"),e("abc".at(-10)===void 0,"负向越界应返回 undefined")}),t("TypedArray.at() —— 支持负索引",function(){var n=new Int32Array([100,200,300,400]);e(n.at(0)===100,"TypedArray.at(0) 应返回第一个元素"),e(n.at(-1)===400,"TypedArray.at(-1) 应返回最后一个元素"),e(n.at(-2)===300,"TypedArray.at(-2) 应返回倒数第二个元素")}),t("at() 不修改原数组",function(){var n=[1,2,3];e(n.length===3&&n[2]===3,"at() 不应修改原数组")}),u()}function testObjectHasOwn(){var a=createSuite("Object.hasOwn() (ES2022)"),t=a.test,e=a.assert,u=a.getResults;return t("基本用法 —— 自有属性返回 true",function(){var n={name:"Alice",age:30};e(Object.hasOwn(n,"name")===!0,"name 是自有属性,应返回 true"),e(Object.hasOwn(n,"age")===!0,"age 是自有属性,应返回 true")}),t("不存在的属性返回 false",function(){var n={a:1};e(Object.hasOwn(n,"b")===!1,"不存在的属性应返回 false"),e(Object.hasOwn(n,"toString")===!1,"原型链上的属性应返回 false")}),t("继承属性返回 false —— 只检查自有属性",function(){var n=_createClass(function o(i){_classCallCheck(this,o),this.name=i}),r=function(o){function i(){return _classCallCheck(this,i),_callSuper(this,i,arguments)}return _inherits(i,o),_createClass(i)}(n),s=new r("Rex");e(Object.hasOwn(s,"name")===!0,"name 是实例自有属性"),e(Object.hasOwn(s,"constructor")===!1,"constructor 在原型上,不是自有属性")}),t("null 原型对象 —— hasOwnProperty 不可用时的安全方案",function(){var n=Object.create(null);n.key="value";var r=!1;try{n.hasOwnProperty("key")}catch{r=!0}e(r,"null 原型对象调用 hasOwnProperty 应抛出错误"),e(Object.hasOwn(n,"key")===!0,"hasOwn 对 null 原型对象应正常工作"),e(Object.hasOwn(n,"other")===!1,"不存在的键应返回 false")}),t("对象覆盖 hasOwnProperty —— hasOwn 不受影响",function(){var n={hasOwnProperty:function(){return!1},secret:42};e(n.hasOwnProperty("secret")===!1,"被覆盖的 hasOwnProperty 返回错误结果"),e(Object.hasOwn(n,"secret")===!0,"hasOwn 不受覆盖影响,结果正确")}),t("值为 undefined 的属性仍返回 true",function(){var n={key:void 0};e(Object.hasOwn(n,"key")===!0,"值为 undefined 的自有属性应返回 true")}),t("Symbol 作为键",function(){var n=Symbol("id"),r=_defineProperty({},n,123);e(Object.hasOwn(r,n)===!0,"Symbol 键的自有属性应返回 true"),e(Object.hasOwn(r,Symbol("id"))===!1,"不同的 Symbol 实例应返回 false")}),t("数组的索引属性",function(){var n=[10,20,30];e(Object.hasOwn(n,0)===!0,"数组索引 0 是自有属性"),e(Object.hasOwn(n,"1")===!0,'字符串索引 "1" 也是自有属性'),e(Object.hasOwn(n,"length")===!0,"length 是数组的自有属性"),e(Object.hasOwn(n,3)===!1,"越界索引应返回 false")}),u()}function testErrorCause(){var a=createSuite("Error Cause (ES2022)"),t=a.test,e=a.assert,u=a.getResults;return t("基本用法 —— cause 属性保存原始错误",function(){var n=new TypeError("原始类型错误"),r=new Error("操作失败",{cause:n});e(r.message==="操作失败","外层错误消息应正确"),e(r.cause===n,"cause 应指向原始错误"),e(r.cause instanceof TypeError,"cause 类型应保留")}),t("所有内置子类均支持 cause",function(){var n=new Error("根因"),r=[new TypeError("类型错误",{cause:n}),new RangeError("范围错误",{cause:n}),new SyntaxError("语法错误",{cause:n})];r.forEach(function(s){e(s.cause===n,"".concat(s.constructor.name," 的 cause 应指向根因"))})}),t("错误链可以多层嵌套",function(){var n=new Error("数据库连接失败"),r=new Error("查询用户失败",{cause:n}),s=new Error("登录接口报错",{cause:r});e(s.cause===r,"第三层 cause 应指向第二层"),e(s.cause.cause===n,"第二层 cause 应指向第一层"),e(s.cause.cause.message==="数据库连接失败","根因消息应可追溯")}),t("不传 cause 时属性为 undefined",function(){var n=new Error("普通错误");e(n.cause===void 0,"未传 cause 时属性应为 undefined")}),t("cause 可以是任意值(不限于 Error)",function(){var n=new Error("原因是字符串",{cause:"网络超时"}),r=new Error("原因是数字",{cause:404}),s=new Error("原因是对象",{cause:{code:"ENOENT"}});e(n.cause==="网络超时","cause 可以是字符串"),e(r.cause===404,"cause 可以是数字"),e(s.cause.code==="ENOENT","cause 可以是对象")}),t("实际应用:fetch 封装中传递原始网络错误",_asyncToGenerator(_regenerator().m(function n(){var r,s,o,i;return _regenerator().w(function(c){for(;;)switch(c.p=c.n){case 0:return s=function(){return s=_asyncToGenerator(_regenerator().m(function l(h){var y;return _regenerator().w(function(p){for(;;)switch(p.p=p.n){case 0:throw p.p=0,new Error("fetch failed: 500");case 1:throw p.p=1,y=p.v,new Error("获取用户 ".concat(h," 失败"),{cause:y});case 2:return p.a(2)}},l,null,[[0,1]])})),s.apply(this,arguments)},r=function(l){return s.apply(this,arguments)},o=null,c.p=1,c.n=2,r(42);case 2:c.n=4;break;case 3:c.p=3,i=c.v,o=i;case 4:e(o!==null,"应捕获到封装后的错误"),e(o.message.includes("42"),"外层错误消息应包含用户 id"),e(o.cause instanceof Error,"cause 应是原始 Error"),e(o.cause.message.includes("500"),"原始错误消息应保留");case 5:return c.a(2)}},n,null,[[1,3]])}))),t("自定义 Error 子类也支持 cause",function(){var n=function(o){function i(c,f){var l;return _classCallCheck(this,i),l=_callSuper(this,i,[c,f]),l.name="AppError",l}return _inherits(i,o),_createClass(i)}(_wrapNativeSuper(Error)),r=new TypeError("底层失败"),s=new n("应用层失败",{cause:r});e(s.name==="AppError","子类名称应正确"),e(s.cause===r,"自定义子类应支持 cause")}),u()}function testRegExpDFlag(){var a=createSuite("RegExp /d flag (ES2022)"),t=a.test,e=a.assert,u=a.getResults,n=function(){try{return new RegExp("x","d").hasIndices===!0}catch{return!1}}();return t("环境支持检测",function(){e(n,"环境不支持 RegExp /d 标志")}),t("hasIndices 属性标识是否启用 /d 标志",function(){if(!n){e(!0,"(跳过:环境不支持 /d 标志)");return}e(new RegExp("x","d").hasIndices===!0,"/d 标志应使 hasIndices 为 true"),e(new RegExp("x").hasIndices===!1,"无 /d 标志时 hasIndices 应为 false")}),t("整体匹配位置 indices[0]",function(){if(!n){e(!0,"(跳过)");return}var r="hello world".match(new RegExp("world","d"));e(Array.isArray(r.indices),"结果应包含 indices 数组"),e(r.indices[0][0]===6,"匹配起始位置应为 6"),e(r.indices[0][1]===11,"匹配结束位置应为 11(不含)"),e("hello world".slice(6,11)==="world","slice 切出来应等于匹配内容")}),t("捕获组位置 indices[n]",function(){if(!n){e(!0,"(跳过)");return}var r=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})","d"),s="日期:2025-06-15".match(r);e(s.indices[1][0]===3&&s.indices[1][1]===7,"年份捕获组位置应为 [3,7]"),e(s.indices[2][0]===8&&s.indices[2][1]===10,"月份捕获组位置应为 [8,10]"),e(s.indices[3][0]===11&&s.indices[3][1]===13,"日期捕获组位置应为 [11,13]")}),t("通过 indices 验证 slice 还原捕获组内容",function(){if(!n){e(!0,"(跳过)");return}var r="姓名:Alice,年龄:30",s=new RegExp("姓名:(\\w+),年龄:(\\d+)","d"),o=r.match(s),i=_slicedToArray(o.indices[1],2),c=i[0],f=i[1],l=_slicedToArray(o.indices[2],2),h=l[0],y=l[1];e(r.slice(c,f)==="Alice","通过 indices 切出的姓名应为 Alice"),e(r.slice(h,y)==="30","通过 indices 切出的年龄应为 30")}),t("具名捕获组的位置 indices.groups",function(){var r,s;if(!n){e(!0,"(跳过)");return}var o=_wrapRegExp(new RegExp("(\\d{4})-(\\d{2})","d"),{year:1,month:2}),i="发布于 2025-06".match(o);e(i.indices.groups!==void 0,"具名组应出现在 indices.groups 中");var c=i.indices.groups,f=c.year,l=c.month;e((r="发布于 2025-06").slice.apply(r,_toConsumableArray(f))==="2025","具名组 year 位置应正确"),e((s="发布于 2025-06").slice.apply(s,_toConsumableArray(l))==="06","具名组 month 位置应正确")}),t("未匹配的可选组 indices 为 undefined",function(){if(!n){e(!0,"(跳过)");return}var r=new RegExp("(a)?(b)","d"),s="b".match(r);e(s.indices[1]===void 0,"未参与匹配的可选组 indices 应为 undefined"),e(Array.isArray(s.indices[2]),"已匹配的组 indices 应为数组")}),t("/d 与 /g 组合 —— exec 每次返回带 indices 的结果",function(){if(!n){e(!0,"(跳过)");return}for(var r=new RegExp("\\d+","dg"),s="a1b22c333",o=[],i;(i=r.exec(s))!==null;)o.push(i.indices[0]);e(o.length===3,"应匹配到 3 个数字"),e(o[0][0]===1,"第一个数字起始位置应为 1"),e(o[1][0]===3,"第二个数字起始位置应为 3"),e(o[2][0]===6,"第三个数字起始位置应为 6")}),u()}function testTopLevelAwait(){return _testTopLevelAwait.apply(this,arguments)}function _testTopLevelAwait(){return _testTopLevelAwait=_asyncToGenerator(_regenerator().m(function a(){var t,e,u,n;return _regenerator().w(function(r){for(;;)switch(r.n){case 0:return t=createSuite("Top-level await (ES2022)"),e=t.test,u=t.assert,n=t.getResults,r.n=1,e("async 函数内的 await 是等价基础能力",_asyncToGenerator(_regenerator().m(function s(){var o;return _regenerator().w(function(i){for(;;)switch(i.n){case 0:return i.n=1,Promise.resolve(42);case 1:o=i.v,u(o===42,"await 在 async 函数顶层应正常工作");case 2:return i.a(2)}},s)})));case 1:return r.n=2,e("await 可以等待动态 import()",_asyncToGenerator(_regenerator().m(function s(){var o,i;return _regenerator().w(function(c){for(;;)switch(c.n){case 0:return o=function(){return Promise.resolve({default:"module-content",util:function(){return"ok"}})},c.n=1,o();case 1:i=c.v,u(i.default==="module-content","await 动态导入应返回模块内容"),u(i.util()==="ok","模块导出的函数应可调用");case 2:return c.a(2)}},s)})));case 2:return r.n=3,e("await 保序 —— 导入方等待模块初始化完成",_asyncToGenerator(_regenerator().m(function s(){var o,i;return _regenerator().w(function(c){for(;;)switch(c.n){case 0:return o=[],c.n=1,_asyncToGenerator(_regenerator().m(function f(){return _regenerator().w(function(l){for(;;)switch(l.n){case 0:return o.push("A:start"),l.n=1,new Promise(function(h){return setTimeout(h,0)});case 1:return o.push("A:ready"),l.a(2,{data:"initialized"})}},f)}))();case 1:i=c.v,o.push("B:use"),u(i.data==="initialized","模块 A 初始化完成后才能被使用"),u(o.join(",")==="A:start,A:ready,B:use","执行顺序应严格保序");case 2:return c.a(2)}},s)})));case 3:return r.n=4,e("await 与条件导入模拟",_asyncToGenerator(_regenerator().m(function s(){var o,i;return _regenerator().w(function(c){for(;;)switch(c.n){case 0:return o=typeof window<"u",c.n=1,Promise.resolve(o?"browser":"node");case 1:i=c.v,u(typeof i=="string","条件 await 应返回字符串平台标识"),u(i==="browser"||i==="node","平台标识应为 browser 或 node");case 2:return c.a(2)}},s)})));case 4:return r.n=5,e("await 错误应在模块加载阶段被捕获",_asyncToGenerator(_regenerator().m(function s(){var o,i;return _regenerator().w(function(c){for(;;)switch(c.p=c.n){case 0:return o=null,c.p=1,c.n=2,Promise.reject(new Error("模块初始化失败"));case 2:c.n=4;break;case 3:c.p=3,i=c.v,o=i;case 4:u(o instanceof Error,"应捕获到 Error"),u(o.message==="模块初始化失败","错误消息应正确传递");case 5:return c.a(2)}},s,null,[[1,3]])})));case 5:return r.n=6,e("await 不阻塞无依赖的兄弟模块(并行加载)",_asyncToGenerator(_regenerator().m(function s(){var o,i,c,f,l,h;return _regenerator().w(function(y){for(;;)switch(y.n){case 0:return o=Date.now(),y.n=1,Promise.all([new Promise(function(p){return setTimeout(function(){return p("A")},10)}),new Promise(function(p){return setTimeout(function(){return p("B")},10)})]);case 1:i=y.v,c=_slicedToArray(i,2),f=c[0],l=c[1],h=Date.now()-o,u(f==="A"&&l==="B","并行 await 两个模块都应成功完成"),u(h<50,"并行执行耗时应远小于串行(~10ms vs ~20ms)");case 2:return y.a(2)}},s)})));case 6:return r.a(2,n())}},a)})),_testTopLevelAwait.apply(this,arguments)}function testIteratorHelpers(){var a=createSuite("Iterator Helpers (ES2025)"),t=a.test,e=a.assert,u=a.getResults,n=typeof Iterator<"u"&&typeof Iterator.from=="function";return t("环境支持检测",function(){e(n,"环境不支持 Iterator Helpers")}),t("Iterator.from() 将可迭代对象转为迭代器",function(){if(!n){e(!0,"(跳过:环境不支持 Iterator.from)");return}var r=Iterator.from([1,2,3]);e(typeof r.next=="function","应返回迭代器对象")}),t(".map() 惰性映射",function(){if(!n){e(!0,"(跳过)");return}var r=Iterator.from([1,2,3]).map(function(s){return s*2}).toArray();e(r.length===3&&r[0]===2&&r[2]===6,"map 结果应为 [2,4,6]")}),t(".filter() 惰性过滤",function(){if(!n){e(!0,"(跳过)");return}var r=Iterator.from([1,2,3,4,5]).filter(function(s){return s%2===0}).toArray();e(r.length===2&&r[0]===2&&r[1]===4,"filter 结果应为 [2,4]")}),t(".take(n) 取前 n 个元素",function(){if(!n){e(!0,"(跳过)");return}var r=Iterator.from([10,20,30,40,50]).take(3).toArray();e(r.length===3&&r[2]===30,"take(3) 应只取前 3 个")}),t(".drop(n) 跳过前 n 个元素",function(){if(!n){e(!0,"(跳过)");return}var r=Iterator.from([1,2,3,4,5]).drop(2).toArray();e(r.length===3&&r[0]===3,"drop(2) 应从第 3 个开始")}),t(".flatMap() 平铺映射",function(){if(!n){e(!0,"(跳过)");return}var r=Iterator.from([1,2,3]).flatMap(function(s){return[s,s*10]}).toArray();e(r.length===6&&r[1]===10&&r[3]===20,"flatMap 应正确展开")}),t(".reduce() 归约",function(){if(!n){e(!0,"(跳过)");return}var r=Iterator.from([1,2,3,4]).reduce(function(s,o){return s+o},0);e(r===10,"reduce 求和应为 10")}),t(".toArray() 转为数组",function(){if(!n){e(!0,"(跳过)");return}var r=Iterator.from(new Set([7,8,9])).toArray();e(Array.isArray(r)&&r.length===3,"toArray 应返回普通数组")}),t(".forEach() 遍历副作用",function(){if(!n){e(!0,"(跳过)");return}var r=[];Iterator.from(["a","b","c"]).forEach(function(s){return r.push(s)}),e(r.join("")==="abc","forEach 应依次访问每个元素")}),t(".some() / .every() 短路判断",function(){if(!n){e(!0,"(跳过)");return}var r=Iterator.from([1,3,4,5]).some(function(o){return o%2===0}),s=Iterator.from([1,2,3]).every(function(o){return o>0});e(r===!0&&s===!0,"some/every 应正确短路求值")}),t(".find() 查找第一个匹配元素",function(){if(!n){e(!0,"(跳过)");return}var r=Iterator.from([1,3,5,6,7]).find(function(s){return s%2===0});e(r===6,"find 应返回第一个偶数 6")}),t("链式调用:map + filter + take",function(){if(!n){e(!0,"(跳过)");return}var r=Iterator.from([1,2,3,4,5,6,7,8]).map(function(s){return s*s}).filter(function(s){return s>10}).take(3).toArray();e(r.length===3&&r[0]===16&&r[2]===36,"链式调用结果应为 [16,25,36]")}),u()}function testSetMethods(){var a=createSuite("New Set Methods (ES2025)"),t=a.test,e=a.assert,u=a.getResults,n=typeof Set.prototype.union=="function";return t("环境支持检测",function(){e(n,"环境不支持 Set 新方法(union/intersection 等)")}),t("union() —— 并集",function(){if(!n){e(!0,"(跳过:环境不支持 Set.prototype.union)");return}var r=new Set([1,2,3]),s=new Set([3,4,5]),o=r.union(s);e(o.size===5&&o.has(1)&&o.has(5),"并集应包含两个集合所有元素")}),t("intersection() —— 交集",function(){if(!n){e(!0,"(跳过)");return}var r=new Set([1,2,3,4]),s=new Set([3,4,5,6]),o=r.intersection(s);e(o.size===2&&o.has(3)&&o.has(4),"交集应只含共同元素 3,4")}),t("difference() —— 差集(A - B)",function(){if(!n){e(!0,"(跳过)");return}var r=new Set([1,2,3,4]),s=new Set([3,4,5]),o=r.difference(s);e(o.size===2&&o.has(1)&&o.has(2)&&!o.has(3),"差集应为 {1,2}")}),t("symmetricDifference() —— 对称差集",function(){if(!n){e(!0,"(跳过)");return}var r=new Set([1,2,3]),s=new Set([2,3,4]),o=r.symmetricDifference(s);e(o.size===2&&o.has(1)&&o.has(4),"对称差集应为 {1,4}")}),t("isSubsetOf() —— 子集判断",function(){if(!n){e(!0,"(跳过)");return}var r=new Set([2,3]),s=new Set([1,2,3,4]);e(r.isSubsetOf(s)===!0,"a ⊆ b 应为 true"),e(s.isSubsetOf(r)===!1,"b ⊆ a 应为 false")}),t("isSupersetOf() —— 超集判断",function(){if(!n){e(!0,"(跳过)");return}var r=new Set([1,2,3,4]),s=new Set([2,3]);e(r.isSupersetOf(s)===!0,"a ⊇ b 应为 true"),e(s.isSupersetOf(r)===!1,"b ⊇ a 应为 false")}),t("isDisjointFrom() —— 不相交判断",function(){if(!n){e(!0,"(跳过)");return}var r=new Set([1,2]),s=new Set([3,4]),o=new Set([2,5]);e(r.isDisjointFrom(s)===!0,"a 与 b 无交集,应为 true"),e(r.isDisjointFrom(o)===!1,"a 与 c 有交集 2,应为 false")}),t("方法返回新 Set,不修改原集合",function(){if(!n){e(!0,"(跳过)");return}var r=new Set([1,2,3]),s=new Set([3,4]),o=r.union(s);e(r.size===3&&s.size===2,"原集合不应被修改"),e(o!==r&&o!==s,"应返回全新的 Set 实例")}),t("接受任意可迭代对象(不限于 Set)",function(){if(!n){e(!0,"(跳过)");return}var r=new Set([1,2,3]),s=r.intersection(new Set([2,3,4]));e(s.size===2&&s.has(2)&&s.has(3),"应支持传入普通数组")}),u()}function testPromiseTry(){return _testPromiseTry.apply(this,arguments)}function _testPromiseTry(){return _testPromiseTry=_asyncToGenerator(_regenerator().m(function a(){var t,e,u,n,r;return _regenerator().w(function(s){for(;;)switch(s.n){case 0:return t=createSuite("Promise.try (ES2025)"),e=t.test,u=t.assert,n=t.getResults,r=typeof Promise.try=="function",s.n=1,e("环境支持检测",_asyncToGenerator(_regenerator().m(function o(){return _regenerator().w(function(i){for(;;)switch(i.n){case 0:if(r){i.n=1;break}return u(!1,"(环境不支持 Promise.try)"),i.a(2);case 1:u(!0,"环境支持 Promise.try");case 2:return i.a(2)}},o)})));case 1:return s.n=2,e("同步函数 —— 返回值转为 resolved",_asyncToGenerator(_regenerator().m(function o(){var i;return _regenerator().w(function(c){for(;;)switch(c.n){case 0:if(r){c.n=1;break}return u(!0,"(跳过:环境不支持 Promise.try)"),c.a(2);case 1:return c.n=2,Promise.try(function(){return 42});case 2:i=c.v,u(i===42,"同步返回值应被 resolve 为 42");case 3:return c.a(2)}},o)})));case 2:return s.n=3,e("同步函数 —— 抛出异常转为 rejected",_asyncToGenerator(_regenerator().m(function o(){var i;return _regenerator().w(function(c){for(;;)switch(c.n){case 0:if(r){c.n=1;break}return u(!0,"(跳过)"),c.a(2);case 1:return i=null,c.n=2,Promise.try(function(){throw new Error("同步错误")}).catch(function(f){i=f});case 2:u(i instanceof Error&&i.message==="同步错误","同步异常应转为 rejected");case 3:return c.a(2)}},o)})));case 3:return s.n=4,e("异步函数 —— resolved 正常透传",_asyncToGenerator(_regenerator().m(function o(){var i;return _regenerator().w(function(c){for(;;)switch(c.n){case 0:if(r){c.n=1;break}return u(!0,"(跳过)"),c.a(2);case 1:return c.n=2,Promise.try(_asyncToGenerator(_regenerator().m(function f(){return _regenerator().w(function(l){for(;;)switch(l.n){case 0:return l.a(2,"async result")}},f)})));case 2:i=c.v,u(i==="async result","异步 resolved 值应透传");case 3:return c.a(2)}},o)})));case 4:return s.n=5,e("异步函数 —— rejected 正常透传",_asyncToGenerator(_regenerator().m(function o(){var i;return _regenerator().w(function(c){for(;;)switch(c.n){case 0:if(r){c.n=1;break}return u(!0,"(跳过)"),c.a(2);case 1:return i=null,c.n=2,Promise.try(_asyncToGenerator(_regenerator().m(function f(){return _regenerator().w(function(l){for(;;)switch(l.n){case 0:throw new Error("异步错误");case 1:return l.a(2)}},f)}))).catch(function(f){i=f});case 2:u(i instanceof Error&&i.message==="异步错误","异步 rejected 应透传");case 3:return c.a(2)}},o)})));case 5:return s.n=6,e("返回已有 Promise —— 直接透传",_asyncToGenerator(_regenerator().m(function o(){var i,c;return _regenerator().w(function(f){for(;;)switch(f.n){case 0:if(r){f.n=1;break}return u(!0,"(跳过)"),f.a(2);case 1:return i=Promise.resolve("original"),f.n=2,Promise.try(function(){return i});case 2:c=f.v,u(c==="original","返回已有 Promise 的值应直接透传");case 3:return f.a(2)}},o)})));case 6:return s.n=7,e("传递参数给回调函数",_asyncToGenerator(_regenerator().m(function o(){var i;return _regenerator().w(function(c){for(;;)switch(c.n){case 0:if(r){c.n=1;break}return u(!0,"(跳过)"),c.a(2);case 1:return c.n=2,Promise.try(function(f,l){return f+l},10,20);case 2:i=c.v,u(i===30,"应能向回调函数传递参数");case 3:return c.a(2)}},o)})));case 7:return s.n=8,e("对比 new Promise —— 捕获同步异常的等价写法",_asyncToGenerator(_regenerator().m(function o(){var i,c,f,l,h,y;return _regenerator().w(function(p){for(;;)switch(p.n){case 0:if(r){p.n=1;break}return u(!0,"(跳过)"),p.a(2);case 1:return i=new Promise(function(S){return S(JSON.parse('{"key":"value"}'))}),c=Promise.try(function(){return JSON.parse('{"key":"value"}')}),p.n=2,Promise.all([i,c]);case 2:f=p.v,l=_slicedToArray(f,2),h=l[0],y=l[1],u(h.key==="value"&&y.key==="value","两种写法结果应一致");case 3:return p.a(2)}},o)})));case 8:return s.a(2,n())}},a)})),_testPromiseTry.apply(this,arguments)}function testRegExpDuplicateGroups(){var a=createSuite("RegExp Duplicate Named Capture Groups (ES2025)"),t=a.test,e=a.assert,u=a.getResults,n=!1;try{new RegExp("(?<a>x)|(?<a>y)"),n=!0}catch{n=!1}return t("环境支持检测",function(){e(n,"环境不支持重复命名捕获组")}),t("同一命名组在不同分支中可重复使用",function(){if(!n){e(!0,"(跳过:环境不支持重复命名捕获组)");return}var r=_wrapRegExp(/(\d{4})-(\d{2})-(\d{2})|(\d{2})\/(\d{2})\/(\d{4})/,{year:[1,6],month:[2,5],day:[3,4]}),s="2025-06-15".match(r),o="15/06/2025".match(r);e(s.groups.year==="2025"&&s.groups.month==="06","格式一:年月应正确解析"),e(o.groups.year==="2025"&&o.groups.month==="06","格式二:年月应正确解析")}),t("同名组只有命中的那个分支有值,另一个为 undefined",function(){if(!n){e(!0,"(跳过)");return}var r=_wrapRegExp(/([A-Z]+)|(\d+)/,{val:[1,2]}),s="ABC".match(r),o="123".match(r);e(s.groups.val==="ABC",'字母分支命中时 val 应为 "ABC"'),e(o.groups.val==="123",'数字分支命中时 val 应为 "123"')}),t("与 String.prototype.replace 命名引用配合使用",function(){if(!n){e(!0,"(跳过)");return}var r=_wrapRegExp(/(\d{4})-(\d{2})-(\d{2})|(\d{2})\/(\d{2})\/(\d{4})/,{y:[1,6],m:[2,4],d:[3,5]}),s="2025-06-15".replace(r,"$<y>/$<m>/$<d>"),o="06/15/2025".replace(r,"$<y>/$<m>/$<d>");e(s==="2025/06/15","格式一替换应得 2025/06/15"),e(o==="2025/06/15","格式二替换应得 2025/06/15")}),t("matchAll 中重复命名组也正常工作",function(){if(!n){e(!0,"(跳过)");return}var r=_wrapRegExp(/([a-z]+)|(\d+)/g,{word:[1,2]}),s=_toConsumableArray("hello 42 world 7".matchAll(r)),o=s.map(function(i){return i.groups.word});e(o.length===4&&o[0]==="hello"&&o[1]==="42","matchAll 应正确提取所有命中词")}),t("非命中分支的同名组值为 undefined",function(){if(!n){e(!0,"(跳过)");return}var r=_wrapRegExp(/(foo)|(bar)/,{a:[1,2]}),s="bar".match(r);e(s.groups.a==="bar","应取命中分支的值")}),u()}function testUint8ArrayBase64Hex(){var a=createSuite("Uint8Array Base64/Hex (ES2025)"),t=a.test,e=a.assert,u=a.getResults,n=typeof Uint8Array.prototype.toBase64=="function";return t("环境支持检测",function(){e(n,"环境不支持 Uint8Array Base64/Hex 方法")}),t("toBase64() —— Uint8Array 转 Base64 字符串",function(){if(!n){e(!0,"(跳过:环境不支持 Uint8Array.toBase64)");return}var r=new Uint8Array([72,101,108,108,111]),s=r.toBase64();e(s==="SGVsbG8=",'toBase64 应返回 "SGVsbG8=",实际: '.concat(s))}),t("fromBase64() —— Base64 字符串转 Uint8Array",function(){if(!n){e(!0,"(跳过)");return}var r=Uint8Array.fromBase64("SGVsbG8=");e(r.length===5&&r[0]===72&&r[4]===111,"fromBase64 应还原为正确字节")}),t("toHex() —— Uint8Array 转十六进制字符串",function(){if(!n){e(!0,"(跳过)");return}var r=new Uint8Array([222,173,190,239]),s=r.toHex();e(s==="deadbeef",'toHex 应返回 "deadbeef",实际: '.concat(s))}),t("fromHex() —— 十六进制字符串转 Uint8Array",function(){if(!n){e(!0,"(跳过)");return}var r=Uint8Array.fromHex("deadbeef");e(r.length===4&&r[0]===222&&r[3]===239,"fromHex 应正确还原字节")}),t("Base64 round-trip(互转验证)",function(){if(!n){e(!0,"(跳过)");return}var r=new Uint8Array([1,2,3,255,0,128]),s=Uint8Array.fromBase64(r.toBase64());e(r.length===s.length&&r.every(function(o,i){return o===s[i]}),"Base64 round-trip 应完全还原原始字节")}),t("Hex round-trip(互转验证)",function(){if(!n){e(!0,"(跳过)");return}var r=new Uint8Array([0,127,128,255]),s=Uint8Array.fromHex(r.toHex());e(r.length===s.length&&r.every(function(o,i){return o===s[i]}),"Hex round-trip 应完全还原原始字节")}),t("空数组 toBase64 返回空字符串",function(){if(!n){e(!0,"(跳过)");return}var r=new Uint8Array([]);e(r.toBase64()==="","空 Uint8Array 的 Base64 应为空字符串")}),t("空字符串 fromHex 返回空 Uint8Array",function(){if(!n){e(!0,"(跳过)");return}var r=Uint8Array.fromHex("");e(r.length===0,"空字符串 fromHex 应返回空 Uint8Array")}),t("toBase64 支持 URL-safe 模式",function(){if(!n){e(!0,"(跳过)");return}var r=new Uint8Array([251,255]),s=r.toBase64(),o=r.toBase64({alphabet:"base64url"});e(o.indexOf("+")===-1&&o.indexOf("/")===-1,"URL-safe Base64 不应含 + 或 /"),e(s!==o||!s.includes("+")&&!s.includes("/"),"URL-safe 与标准编码结果应存在差异(或均不含特殊字符)")}),u()}function testJsonParseSource(){var a=createSuite("JSON.parse Source Text Access (ES2025)"),t=a.test,e=a.assert,u=a.getResults,n=!1;try{JSON.parse("1",function(r,s,o){return o&&typeof o.source=="string"&&(n=!0),s})}catch{}return t("环境支持检测",function(){e(n,"环境不支持 JSON.parse source text access")}),t("reviver 接收第三个参数 context",function(){if(!n){e(!0,"(跳过:环境不支持 JSON.parse source text access)");return}var r=null;JSON.parse('"hello"',function(s,o,i){return s===""&&(r=i),o}),e(r!==null&&typeof r.source=="string","reviver 应收到含 source 属性的 context 对象")}),t("context.source 为该值的原始 JSON 文本",function(){if(!n){e(!0,"(跳过)");return}var r={};JSON.parse('{"a": 42, "b": "hello"}',function(s,o,i){return s!==""&&(r[s]=i.source),o}),e(r.a==="42",'数字的 source 应为 "42",实际: "'.concat(r.a,'"')),e(r.b==='"hello"',`字符串的 source 应为 '"hello"',实际: "`.concat(r.b,'"'))}),t("利用 source 精确解析超大整数(BigInt)",function(){if(!n){e(!0,"(跳过)");return}var r="9007199254740993",s=JSON.parse('{"id":'.concat(r,"}"),function(o,i,c){return o===""?i:/^\d+$/.test(c.source)?BigInt(c.source):i});e(typeof s.id=="bigint","超大整数应被转为 BigInt"),e(s.id===BigInt(r),"BigInt 值应精确等于 ".concat(r))}),t("嵌套对象中每个值都能获取自己的 source",function(){if(!n){e(!0,"(跳过)");return}var r=[];JSON.parse('{"x":1,"arr":[2,3]}',function(s,o,i){return s!==""&&r.push(i.source),o}),e(r.includes("1")&&r.includes("2")&&r.includes("3"),"嵌套结构中每个原始值都应能取到 source")}),t("null / boolean 也有对应 source",function(){if(!n){e(!0,"(跳过)");return}var r={};JSON.parse('{"a":null,"b":true,"c":false}',function(s,o,i){return s!==""&&(r[s]=i.source),o}),e(r.a==="null"&&r.b==="true"&&r.c==="false","null/true/false 的 source 应为对应的原始文本")}),u()}function testErrorIsError(){var a=createSuite("Error.isError (ES2025)"),t=a.test,e=a.assert,u=a.getResults,n=typeof Error.isError=="function";return t("环境支持检测",function(){e(n,"环境不支持 Error.isError")}),t("原生 Error 实例返回 true",function(){if(!n){e(!0,"(跳过:环境不支持 Error.isError)");return}e(Error.isError(new Error("test"))===!0,"new Error() 应返回 true")}),t("Error 子类实例返回 true",function(){if(!n){e(!0,"(跳过)");return}e(Error.isError(new TypeError("type"))===!0,"TypeError 应返回 true"),e(Error.isError(new RangeError("range"))===!0,"RangeError 应返回 true"),e(Error.isError(new SyntaxError("syntax"))===!0,"SyntaxError 应返回 true"),e(Error.isError(new ReferenceError("ref"))===!0,"ReferenceError 应返回 true"),e(Error.isError(new URIError("uri"))===!0,"URIError 应返回 true"),e(Error.isError(new EvalError("eval"))===!0,"EvalError 应返回 true")}),t("自定义 Error 子类实例返回 true",function(){if(!n){e(!0,"(跳过)");return}var r=function(s){function o(i){var c;return _classCallCheck(this,o),c=_callSuper(this,o,[i]),c.name="AppError",c}return _inherits(o,s),_createClass(o)}(_wrapNativeSuper(Error));e(Error.isError(new r("app"))===!0,"自定义 Error 子类应返回 true")}),t("普通对象返回 false",function(){if(!n){e(!0,"(跳过)");return}e(Error.isError({})===!1,"普通对象应返回 false"),e(Error.isError({message:"fake",stack:""})===!1,"伪造 Error 对象应返回 false")}),t("模拟 Error 对象(纯 JS 构造)返回 false",function(){if(!n){e(!0,"(跳过)");return}var r=Object.create(Error.prototype);r.message="fake",e(Error.isError(null)===!1,"null 应返回 false"),e(Error.isError(void 0)===!1,"undefined 应返回 false"),e(Error.isError(42)===!1,"数字应返回 false"),e(Error.isError("error")===!1,'字符串 "error" 应返回 false')}),t("数组、函数、正则等非 Error 值返回 false",function(){if(!n){e(!0,"(跳过)");return}e(Error.isError([])===!1,"数组应返回 false"),e(Error.isError(function(){})===!1,"函数应返回 false"),e(Error.isError(/regex/)===!1,"正则应返回 false"),e(Error.isError(new Date)===!1,"Date 应返回 false")}),t("实际使用场景:统一捕获并判断 catch 的值",function(){if(!n){e(!0,"(跳过)");return}function r(o){if(o)throw new TypeError("类型错误");return Promise.reject("string rejection")}var s=null;try{r(!0)}catch(o){s=o}e(Error.isError(s)===!0,"try/catch 捕获的 Error 应识别为 true"),e(Error.isError("string rejection")===!1,"字符串 rejection 应识别为 false")}),u()}function testFloat16Array(){var a=createSuite("Float16Array (ES2025)"),t=a.test,e=a.assert,u=a.getResults,n=typeof Float16Array<"u";return t("环境支持检测",function(){e(n,"环境不支持 Float16Array")}),t("Float16Array 可正常创建",function(){if(!n){e(!0,"(跳过:环境不支持 Float16Array)");return}var r=new Float16Array(4);e(r.length===4,"Float16Array 长度应为 4"),e(r.BYTES_PER_ELEMENT===2,"每个元素应占 2 字节(16 位)")}),t("从数组初始化并读取值",function(){if(!n){e(!0,"(跳过)");return}var r=new Float16Array([1,.5,-1,0]);e(r[0]===1,"arr[0] 应为 1.0"),e(r[1]===.5,"arr[1] 应为 0.5"),e(r[2]===-1,"arr[2] 应为 -1.0"),e(r[3]===0,"arr[3] 应为 0.0")}),t("Math.f16round() 舍入到最近 float16 值",function(){if(typeof Math.f16round!="function"){e(!0,"(跳过:环境不支持 Math.f16round)");return}var r=Math.f16round(1.337);e(typeof r=="number","Math.f16round 应返回数字"),e(Math.abs(r-1.337)<.01,"舍入误差应在 0.01 以内"),e(r!==1.337,"应发生精度损失,结果不等于输入值")}),t("Math.f16round(Infinity) / (-Infinity) / NaN 特殊值",function(){if(typeof Math.f16round!="function"){e(!0,"(跳过)");return}e(Math.f16round(1/0)===1/0,"Infinity 应保持不变"),e(Math.f16round(-1/0)===-1/0,"-Infinity 应保持不变"),e(Number.isNaN(Math.f16round(NaN)),"NaN 应保持 NaN"),e(Math.f16round(0)===0,"0 应保持 0")}),t("DataView.getFloat16 / setFloat16",function(){if(!n){e(!0,"(跳过)");return}var r=new DataView(new ArrayBuffer(4));if(typeof r.setFloat16!="function"){e(!0,"(跳过:DataView 不支持 float16)");return}r.setFloat16(0,1.5,!0);var s=r.getFloat16(0,!0);e(s===1.5,"DataView setFloat16/getFloat16 round-trip 应还原 1.5")}),t("Float16Array 支持 TypedArray 通用方法",function(){if(!n){e(!0,"(跳过)");return}var r=new Float16Array([3,1,4,1,5]);r.sort(),e(r[0]===1&&r[4]===5,"sort 后最小值应为 1,最大值应为 5");var s=r.map(function(o){return o*2});e(s instanceof Float16Array,"map 应返回 Float16Array")}),t("Float16Array 内存占用是 Float32Array 的一半",function(){if(!n){e(!0,"(跳过)");return}var r=100,s=new Float16Array(r),o=new Float32Array(r);e(s.byteLength===o.byteLength/2,"Float16Array 字节长度应是 Float32Array 的一半")}),u()}function testMathSumPrecise(){var a=createSuite("Math.sumPrecise() (ES2026)"),t=a.test,e=a.assert,u=a.getResults,n=typeof Math.sumPrecise=="function";return t("环境支持检测",function(){e(n,"环境不支持 Math.sumPrecise")}),t("基本求和 —— 整数",function(){if(!n){e(!0,"(跳过:环境不支持 Math.sumPrecise)");return}e(Math.sumPrecise([1,2,3,4,5])===15,"整数求和应为 15"),e(Math.sumPrecise([])===0,"空数组求和应为 0"),e(Math.sumPrecise([42])===42,"单元素求和应为自身")}),t("精确处理浮点数累积误差",function(){if(!n){e(!0,"(跳过)");return}var r=[.1,.2,.3].reduce(function(o,i){return o+i}),s=Math.sumPrecise([.1,.2,.3]);e(r!==.6,"普通 reduce 应存在浮点误差(验证前提)"),e(s===.6,"Math.sumPrecise 应精确返回 0.6")}),t("大量小数精确求和",function(){if(!n){e(!0,"(跳过)");return}var r=1/3,s=Math.sumPrecise([r,r,r]);e(typeof s=="number","应返回数值类型"),e(s>.999&&s<=1,"三个 1/3 之和应尽量接近 1")}),t("接受任意可迭代对象",function(){var r=_regenerator().m(o);if(!n){e(!0,"(跳过)");return}var s=Math.sumPrecise(new Set([10,20,30]));e(s===60,"支持 Set 可迭代对象");function o(){return _regenerator().w(function(c){for(;;)switch(c.n){case 0:return c.n=1,1;case 1:return c.n=2,2;case 2:return c.n=3,3;case 3:return c.a(2)}},r)}var i=Math.sumPrecise(o());e(i===6,"支持 Generator 可迭代对象")}),t("特殊值处理",function(){if(!n){e(!0,"(跳过)");return}e(Math.sumPrecise([0])===0,"+0 求和应为 0"),e(Math.sumPrecise([-0])===0,"-0 求和应为 0(结果为 +0)"),e(Math.sumPrecise([1,1/0])===1/0,"含 Infinity 结果应为 Infinity"),e(Math.sumPrecise([-1/0,1])===-1/0,"含 -Infinity 结果应为 -Infinity"),e(Number.isNaN(Math.sumPrecise([1/0,-1/0])),"Inf + (-Inf) 应为 NaN"),e(Number.isNaN(Math.sumPrecise([1,NaN,3])),"含 NaN 结果应为 NaN")}),t("非数值元素应抛出 TypeError",function(){if(!n){e(!0,"(跳过)");return}var r=!1;try{Math.sumPrecise([1,"2",3])}catch(s){r=s instanceof TypeError}e(r,"非数值元素应抛出 TypeError")}),u()}function testRegExpEscape(){var a=createSuite("RegExp.escape() (ES2026)"),t=a.test,e=a.assert,u=a.getResults,n=typeof RegExp.escape=="function";return t("环境支持检测",function(){e(n,"环境不支持 RegExp.escape")}),t("转义正则特殊字符",function(){if(!n){e(!0,"(跳过:环境不支持 RegExp.escape)");return}var r="^$.*+?()[]{}|\\",s=RegExp.escape(r);e(typeof s=="string","应返回字符串"),e(s.includes("\\^"),"^ 应被转义"),e(s.includes("\\$"),"$ 应被转义"),e(s.includes("\\."),". 应被转义"),e(s.includes("\\*"),"* 应被转义")}),t("转义结果可安全构造正则",function(){if(!n){e(!0,"(跳过)");return}var r="price: $10.00 (sale!)",s=new RegExp(RegExp.escape(r));e(s.test("price: $10.00 (sale!)"),"转义后的正则应能精确匹配原字符串"),e(!s.test("price: X10X00 Xsale!"),"不应匹配用特殊字符替换后的字符串")}),t("防止正则注入攻击",function(){if(!n){e(!0,"(跳过)");return}var r="(.*)",s=new RegExp(r),o=new RegExp(RegExp.escape(r));e(s.test("anything"),"未转义的正则可匹配任意字符串(注入漏洞)"),e(!o.test("anything"),'转义后只能匹配字面量 "(.*)"'),e(o.test("(.*)"),'转义后精确匹配字面字符串 "(.*)"')}),t("中文等 Unicode 字符不应被转义",function(){if(!n){e(!0,"(跳过)");return}var r="你好,世界";e(RegExp.escape(r)===r,"Unicode 字符不需要转义")}),t("空字符串返回空字符串",function(){if(!n){e(!0,"(跳过)");return}e(RegExp.escape("")==="","空字符串转义后应仍为空字符串")}),t("与 /g 标志组合 —— 高亮搜索词",function(){if(!n){e(!0,"(跳过)");return}var r="商品价格 $10.00,原价 $20.00",s="$10.00",o=new RegExp(RegExp.escape(s),"g"),i=(r.match(o)||[]).length;e(i===1,"含特殊字符的关键词应精确匹配 1 次")}),u()}function testExplicitResourceManagement(){return _testExplicitResourceManagement.apply(this,arguments)}function _testExplicitResourceManagement(){return _testExplicitResourceManagement=_asyncToGenerator(_regenerator().m(function a(){var t,e,u,n,r;return _regenerator().w(function(s){for(;;)switch(s.n){case 0:return t=createSuite("Explicit Resource Management (ES2026)"),e=t.test,u=t.assert,n=t.getResults,r=function(){try{return new Function("Symbol",`
|
|
4
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ownKeys(a,t){var e=Object.keys(a);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(a);t&&(i=i.filter(function(n){return Object.getOwnPropertyDescriptor(a,n).enumerable})),e.push.apply(e,i)}return e}function _objectSpread2(a){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?ownKeys(Object(e),!0).forEach(function(i){_defineProperty(a,i,e[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(e)):ownKeys(Object(e)).forEach(function(i){Object.defineProperty(a,i,Object.getOwnPropertyDescriptor(e,i))})}return a}function _possibleConstructorReturn(a,t){if(t&&(typeof t=="object"||typeof t=="function"))return t;if(t!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(a)}function _regenerator(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var a,t,e=typeof Symbol=="function"?Symbol:{},i=e.iterator||"@@iterator",n=e.toStringTag||"@@toStringTag";function r(y,p,S,M){var F=p&&p.prototype instanceof o?p:o,k=Object.create(F.prototype);return _regeneratorDefine(k,"_invoke",function(j,N,T){var b,d,m,P=0,I=T||[],A=!1,_={p:0,n:0,v:a,a:R,f:R.bind(a,4),d:function(w,v){return b=w,d=0,m=a,_.n=v,s}};function R(w,v){for(d=w,m=v,t=0;!A&&P&&!E&&t<I.length;t++){var E,g=I[t],C=_.p,O=g[2];w>3?(E=O===v)&&(m=g[(d=g[4])?5:(d=3,3)],g[4]=g[5]=a):g[0]<=C&&((E=w<2&&C<g[1])?(d=0,_.v=v,_.n=g[1]):C<O&&(E=w<3||g[0]>v||v>O)&&(g[4]=w,g[5]=v,_.n=O,d=0))}if(E||w>1)return s;throw A=!0,v}return function(w,v,E){if(P>1)throw TypeError("Generator is already running");for(A&&v===1&&R(v,E),d=v,m=E;(t=d<2?a:m)||!A;){b||(d?d<3?(d>1&&(_.n=-1),R(d,m)):_.n=m:_.v=m);try{if(P=2,b){if(d||(w="next"),t=b[w]){if(!(t=t.call(b,m)))throw TypeError("iterator result is not an object");if(!t.done)return t;m=t.value,d<2&&(d=0)}else d===1&&(t=b.return)&&t.call(b),d<2&&(m=TypeError("The iterator does not provide a '"+w+"' method"),d=1);b=a}else if((t=(A=_.n<0)?m:j.call(N,_))!==s)break}catch(g){b=a,d=1,m=g}finally{P=1}}return{value:t,done:A}}}(y,S,M),!0),k}var s={};function o(){}function u(){}function c(){}t=Object.getPrototypeOf;var f=[][i]?t(t([][i]())):(_regeneratorDefine(t={},i,function(){return this}),t),l=c.prototype=o.prototype=Object.create(f);function h(y){return Object.setPrototypeOf?Object.setPrototypeOf(y,c):(y.__proto__=c,_regeneratorDefine(y,n,"GeneratorFunction")),y.prototype=Object.create(l),y}return u.prototype=c,_regeneratorDefine(l,"constructor",c),_regeneratorDefine(c,"constructor",u),u.displayName="GeneratorFunction",_regeneratorDefine(c,n,"GeneratorFunction"),_regeneratorDefine(l),_regeneratorDefine(l,n,"Generator"),_regeneratorDefine(l,i,function(){return this}),_regeneratorDefine(l,"toString",function(){return"[object Generator]"}),(_regenerator=function(){return{w:r,m:h}})()}function _regeneratorDefine(a,t,e,i){var n=Object.defineProperty;try{n({},"",{})}catch{n=0}_regeneratorDefine=function(r,s,o,u){function c(f,l){_regeneratorDefine(r,f,function(h){return this._invoke(f,l,h)})}s?n?n(r,s,{value:o,enumerable:!u,configurable:!u,writable:!u}):r[s]=o:(c("next",0),c("throw",1),c("return",2))},_regeneratorDefine(a,t,e,i)}function _setPrototypeOf(a,t){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,i){return e.__proto__=i,e},_setPrototypeOf(a,t)}function _slicedToArray(a,t){return _arrayWithHoles(a)||_iterableToArrayLimit(a,t)||_unsupportedIterableToArray(a,t)||_nonIterableRest()}function _superPropBase(a,t){for(;!{}.hasOwnProperty.call(a,t)&&(a=_getPrototypeOf(a))!==null;);return a}function _superPropGet(a,t,e,i){var n=_get(_getPrototypeOf(1&i?a.prototype:a),t,e);return 2&i&&typeof n=="function"?function(r){return n.apply(e,r)}:n}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_unsupportedIterableToArray(a)||_nonIterableSpread()}function _toPrimitive(a,t){if(typeof a!="object"||!a)return a;var e=a[Symbol.toPrimitive];if(e!==void 0){var i=e.call(a,t||"default");if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(a)}function _toPropertyKey(a){var t=_toPrimitive(a,"string");return typeof t=="symbol"?t:t+""}function _typeof(a){"@babel/helpers - typeof";return _typeof=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_typeof(a)}function _unsupportedIterableToArray(a,t){if(a){if(typeof a=="string")return _arrayLikeToArray(a,t);var e={}.toString.call(a).slice(8,-1);return e==="Object"&&a.constructor&&(e=a.constructor.name),e==="Map"||e==="Set"?Array.from(a):e==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?_arrayLikeToArray(a,t):void 0}}function _usingCtx(){var a=typeof SuppressedError=="function"?SuppressedError:function(n,r){var s=Error();return s.name="SuppressedError",s.error=n,s.suppressed=r,s},t={},e=[];function i(n,r){if(r!=null){if(Object(r)!==r)throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");if(n)var s=r[Symbol.asyncDispose||Symbol.for("Symbol.asyncDispose")];if(s===void 0&&(s=r[Symbol.dispose||Symbol.for("Symbol.dispose")],n))var o=s;if(typeof s!="function")throw new TypeError("Object is not disposable.");o&&(s=function(){try{o.call(r)}catch(u){return Promise.reject(u)}}),e.push({v:r,d:s,a:n})}else n&&e.push({d:r,a:n});return r}return{e:t,u:i.bind(null,!1),a:i.bind(null,!0),d:function(){var n,r=this.e,s=0;function o(){for(;n=e.pop();)try{if(!n.a&&s===1)return s=0,e.push(n),Promise.resolve().then(o);if(n.d){var c=n.d.call(n.v);if(n.a)return s|=2,Promise.resolve(c).then(o,u)}else s|=1}catch(f){return u(f)}if(s===1)return r!==t?Promise.reject(r):Promise.resolve();if(r!==t)throw r}function u(c){return r=r!==t?new a(c,r):c,o()}return o()}}}function _wrapNativeSuper(a){var t=typeof Map=="function"?new Map:void 0;return _wrapNativeSuper=function(e){if(e===null||!_isNativeFunction(e))return e;if(typeof e!="function")throw new TypeError("Super expression must either be null or a function");if(t!==void 0){if(t.has(e))return t.get(e);t.set(e,i)}function i(){return _construct(e,arguments,_getPrototypeOf(this).constructor)}return i.prototype=Object.create(e.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(i,e)},_wrapNativeSuper(a)}function _wrapRegExp(){_wrapRegExp=function(n,r){return new e(n,void 0,r)};var a=RegExp.prototype,t=new WeakMap;function e(n,r,s){var o=RegExp(n,r);return t.set(o,s||t.get(n)),_setPrototypeOf(o,e.prototype)}function i(n,r){var s=t.get(r);return Object.keys(s).reduce(function(o,u){var c=s[u];if(typeof c=="number")o[u]=n[c];else{for(var f=0;n[c[f]]===void 0&&f+1<c.length;)f++;o[u]=n[c[f]]}return o},Object.create(null))}return _inherits(e,RegExp),e.prototype.exec=function(n){var r=a.exec.call(this,n);if(r){r.groups=i(r,this);var s=r.indices;s&&(s.groups=i(s,this))}return r},e.prototype[Symbol.replace]=function(n,r){if(typeof r=="string"){var s=t.get(this);return a[Symbol.replace].call(this,n,r.replace(/\$<([^>]+)(>|$)/g,function(u,c,f){if(f==="")return u;var l=s[c];return Array.isArray(l)?"$"+l.join("$"):typeof l=="number"?"$"+l:""}))}if(typeof r=="function"){var o=this;return a[Symbol.replace].call(this,n,function(){var u=arguments;return typeof u[u.length-1]!="object"&&(u=[].slice.call(u)).push(i(u,o)),r.apply(this,u)})}return a[Symbol.replace].call(this,n,r)},_wrapRegExp.apply(this,arguments)}function createSuite(a){var t=[];function e(r,s){try{var o=s();if(o instanceof Promise)return o.then(function(){t.push({suite:a,case:r,status:"pass"})}).catch(function(u){t.push({suite:a,case:r,status:"fail",error:u.message})});t.push({suite:a,case:r,status:"pass"})}catch(u){t.push({suite:a,case:r,status:"fail",error:u.message})}}function i(r,s){if(!r)throw new Error(s||"断言失败")}function n(){return t}return{test:e,assert:i,getResults:n}}function printResults(a){var t=0,e=0;a.forEach(function(i){i.status==="pass"?(t++,console.log(" ✓ [".concat(i.suite,"] ").concat(i.case))):(e++,console.error(" ✗ [".concat(i.suite,"] ").concat(i.case," — ").concat(i.error)))}),console.log(`
|
|
5
|
+
共 `.concat(a.length," 项,通过 ").concat(t,",失败 ").concat(e))}function testLetConst(){var a=createSuite("let & const"),t=a.test,e=a.assert,i=a.getResults;return t("let 块级作用域",function(){for(var n=[],r=0;r<3;r++)n.push(r);e(n[0]===0&&n[2]===2,"let 循环变量应为独立值")}),t("const 声明常量",function(){var n=3.14159;e(n===3.14159,"const 值应保持不变")}),i()}function testArrowFunctions(){var a=createSuite("箭头函数"),t=a.test,e=a.assert,i=a.getResults;return t("基本语法",function(){var n=function(s,o){return s+o};e(n(2,3)===5,"箭头函数返回值应为 5")}),i()}function testTemplateLiterals(){var a=createSuite("模板字符串"),t=a.test,e=a.assert,i=a.getResults;return t("基本插值",function(){var n="ES2015",r="Hello, ".concat(n,"!");e(r==="Hello, ES2015!","模板字符串插值应正确")}),i()}function testDestructuring(){var a=createSuite("解构赋值"),t=a.test,e=a.assert,i=a.getResults;return t("数组解构 - 基本",function(){var n=3;e(n===3,"数组解构基本用法")}),t("数组解构 - 跳过元素",function(){var n=[1,2,3,4],r=n[3];e(r===4,"数组解构可跳过元素")}),i()}function testDefaultRestSpread(){var a=createSuite("默认参数/Rest/Spread"),t=a.test,e=a.assert,i=a.getResults;return t("spread 对象覆盖属性",function(){var n={a:1,b:2},r=_objectSpread2(_objectSpread2({},n),{},{b:99});e(r.b===99,"spread 后面属性覆盖前面")}),i()}function testClasses(){var a=createSuite("类(Class)"),t=a.test,e=a.assert,i=a.getResults;return t("基本类定义",function(){var n=function(){function s(o){_classCallCheck(this,s),this.name=o}return _createClass(s,[{key:"speak",value:function(){return"".concat(this.name," makes a sound.")}}])}(),r=new n("Cat");e(r.name==="Cat","构造函数应正确赋值"),e(r.speak()==="Cat makes a sound.","实例方法应正常工作")}),t("类继承",function(){var n=function(){function o(u){_classCallCheck(this,o),this.name=u}return _createClass(o,[{key:"speak",value:function(){return"".concat(this.name,": ...")}}])}(),r=function(o){function u(){return _classCallCheck(this,u),_callSuper(this,u,arguments)}return _inherits(u,o),_createClass(u,[{key:"speak",value:function(){return"".concat(this.name,": Woof!")}}])}(n),s=new r("Rex");e(s.speak()==="Rex: Woof!","子类应覆盖父类方法"),e(s instanceof r&&s instanceof n,"instanceof 检查应通过")}),t("super 调用父类方法",function(){var n=function(){function o(){_classCallCheck(this,o)}return _createClass(o,[{key:"area",value:function(){return 0}},{key:"describe",value:function(){return"面积: ".concat(this.area())}}])}(),r=function(o){function u(c){var f;return _classCallCheck(this,u),f=_callSuper(this,u),f.r=c,f}return _inherits(u,o),_createClass(u,[{key:"area",value:function(){return Math.PI*this.r*this.r}},{key:"describe",value:function(){return _superPropGet(u,"describe",this,3)([])+" (圆形)"}}])}(n),s=new r(1);e(s.describe().includes("面积:"),"super 方法调用")}),t("静态方法",function(){var n=function(){function r(){_classCallCheck(this,r)}return _createClass(r,null,[{key:"add",value:function(o,u){return o+u}}])}();_defineProperty(n,"PI",3.14159),e(n.add(2,3)===5,"静态方法应直接通过类调用"),e(n.PI===3.14159,"静态属性应正确设置")}),t("getter 和 setter",function(){var n=function(){function s(o){_classCallCheck(this,s),this._celsius=o}return _createClass(s,[{key:"fahrenheit",get:function(){return this._celsius*9/5+32},set:function(u){this._celsius=(u-32)*5/9}}])}(),r=new n(0);e(r.fahrenheit===32,"getter 应正确计算"),r.fahrenheit=212,e(Math.round(r._celsius)===100,"setter 应正确转换")}),t("私有字段 (#)",function(){var n=new WeakMap,r=function(){function o(){_classCallCheck(this,o),_classPrivateFieldInitSpec(this,n,0)}return _createClass(o,[{key:"increment",value:function(){var c;_classPrivateFieldSet2(n,this,(c=_classPrivateFieldGet2(n,this),c++,c))}},{key:"value",get:function(){return _classPrivateFieldGet2(n,this)}}])}(),s=new r;s.increment(),s.increment(),e(s.value===2,"私有字段应正确工作"),e(!("count"in s),"私有字段不可从外部访问")}),t("类表达式",function(){var n=function(){function s(o,u){_classCallCheck(this,s),this.w=o,this.h=u}return _createClass(s,[{key:"area",value:function(){return this.w*this.h}}])}(),r=new n(3,4);e(r.area()===12,"类表达式应正常工作")}),t("类不存在变量提升",function(){try{new Function('"use strict"; new Foo(); class Foo {}')(),e(!1,"应抛出 ReferenceError")}catch{e(!0,"类不提升,使用前必须先声明")}}),i()}function testPromises(){return _testPromises.apply(this,arguments)}function _testPromises(){return _testPromises=_asyncToGenerator(_regenerator().m(function a(){var t,e,i,n,r;return _regenerator().w(function(s){for(;;)switch(s.n){case 0:return t=createSuite("Promise"),e=t.test,i=t.assert,n=t.getResults,r=[],r.push(e("基本 Promise resolve",function(){return new Promise(function(o){return o(42)}).then(function(o){return i(o===42,"resolve 值应为 42")})})),r.push(e("基本 Promise reject",function(){return new Promise(function(o,u){return u(new Error("失败"))}).catch(function(o){return i(o.message==="失败","reject 应携带错误信息")})})),r.push(e("Promise 链式调用",function(){return Promise.resolve(1).then(function(o){return o+1}).then(function(o){return o*3}).then(function(o){return i(o===6,"链式调用结果应为 6")})})),r.push(e("Promise.all - 全部成功",function(){return Promise.all([Promise.resolve(1),Promise.resolve(2),Promise.resolve(3)]).then(function(o){return i(o.join(",")==="1,2,3","Promise.all 应返回所有结果")})})),r.push(e("Promise.all - 一个失败则全部失败",function(){return Promise.all([Promise.resolve(1),Promise.reject(new Error("error")),Promise.resolve(3)]).catch(function(o){return i(o.message==="error","Promise.all 中有失败应 reject")})})),r.push(e("Promise.race - 返回最快的结果",function(){var o=new Promise(function(c){return setTimeout(function(){return c("slow")},100)}),u=Promise.resolve("fast");return Promise.race([o,u]).then(function(c){return i(c==="fast","Promise.race 应返回最快完成的")})})),r.push(e("Promise.allSettled - 全部结果",function(){return Promise.allSettled([Promise.resolve(1),Promise.reject("err")]).then(function(o){i(o[0].status==="fulfilled","allSettled fulfilled"),i(o[1].status==="rejected","allSettled rejected")})})),r.push(e("Promise.any - 返回第一个成功",function(){return Promise.any([Promise.reject("e1"),Promise.resolve("ok"),Promise.resolve("ok2")]).then(function(o){return i(o==="ok","Promise.any 应返回第一个成功的值")})})),r.push(e("async/await 基本用法",_asyncToGenerator(_regenerator().m(function o(){var u,c,f;return _regenerator().w(function(l){for(;;)switch(l.n){case 0:return c=function(){return c=_asyncToGenerator(_regenerator().m(function y(){var p;return _regenerator().w(function(S){for(;;)switch(S.n){case 0:return S.n=1,Promise.resolve("data");case 1:return p=S.v,S.a(2,p)}},y)})),c.apply(this,arguments)},u=function(){return c.apply(this,arguments)},l.n=1,u();case 1:f=l.v,i(f==="data","async/await 应正确获取异步结果");case 2:return l.a(2)}},o)})))),r.push(e("async/await 错误处理",_asyncToGenerator(_regenerator().m(function o(){var u,c,f;return _regenerator().w(function(l){for(;;)switch(l.p=l.n){case 0:return c=function(){return c=_asyncToGenerator(_regenerator().m(function y(){return _regenerator().w(function(p){for(;;)switch(p.n){case 0:throw new Error("async error");case 1:return p.a(2)}},y)})),c.apply(this,arguments)},u=function(){return c.apply(this,arguments)},l.p=1,l.n=2,u();case 2:i(!1,"应抛出错误"),l.n=4;break;case 3:l.p=3,f=l.v,i(f.message==="async error","async/await 错误处理");case 4:return l.a(2)}},o,null,[[1,3]])})))),s.n=1,Promise.all(r.filter(Boolean));case 1:return s.a(2,n())}},a)})),_testPromises.apply(this,arguments)}function testSymbols(){var a=createSuite("Symbol"),t=a.test,e=a.assert,i=a.getResults;return t("Symbol 唯一性",function(){var n=Symbol("desc"),r=Symbol("desc");e(n!==r,"相同描述的 Symbol 不相等")}),i()}function testIteratorsGenerators(){var a=createSuite("迭代器与生成器"),t=a.test,e=a.assert,i=a.getResults;return t("自定义迭代器",function(){function n(s){var o=0;return{next:function(){return o<s.length?{value:s[o++],done:!1}:{value:void 0,done:!0}}}}var r=n([1,2,3]);e(r.next().value===1,"第一次 next 返回 1"),e(r.next().value===2,"第二次 next 返回 2"),e(r.next().done===!1,"第三次未完成"),e(r.next().done===!0,"第四次完成")}),t("可迭代对象 for...of",function(){for(var n=[],r=0,s=[10,20,30];r<s.length;r++){var o=s[r];n.push(o)}e(n.join(",")==="10,20,30","for...of 迭代数组")}),i()}function testMapSet(){var a=createSuite("Map & Set"),t=a.test,e=a.assert,i=a.getResults;return t("Map 基本操作",function(){var n=new Map;n.set("a",1),n.set("b",2),e(n.get("a")===1,"Map.get 应返回正确值"),e(n.has("b")===!0,"Map.has 应返回 true"),e(n.size===2,"Map.size 应为 2"),n.delete("a"),e(n.size===1,"删除后 size 应为 1")}),i()}function testProxyReflect(){var a=createSuite("Proxy & Reflect"),t=a.test,e=a.assert,i=a.getResults;return t("Proxy get 拦截",function(){var n={get:function(o,u){return u in o?o[u]:'属性 "'.concat(u,'" 不存在')}},r=new Proxy({name:"Alice"},n);e(r.name==="Alice","Proxy get 已有属性"),e(r.age==='属性 "age" 不存在',"Proxy get 不存在属性")}),t("Proxy set 拦截与验证",function(){var n={set:function(o,u,c){if(typeof c!="number")throw new TypeError("只允许数字");return o[u]=c,!0}},r=new Proxy({},n);r.score=90,e(r.score===90,"Proxy set 数字");try{r.score="hello",e(!1,"应抛出 TypeError")}catch(s){e(s instanceof TypeError,"Proxy set 类型校验")}}),i()}function testEnhancedObjects(){var a=createSuite("增强对象字面量"),t=a.test,e=a.assert,i=a.getResults;return t("属性简写",function(){var n="Alice",r=25,s={name:n,age:r};e(s.age===25,"属性简写")}),t("方法简写",function(){var n={greet:function(s){return"Hello, ".concat(s,"!")}};e(n.greet("Bob")==="Hello, Bob!","方法简写")}),i()}function testNewMethods(){var a=createSuite("新增内置方法"),t=a.test,e=a.assert,i=a.getResults;return t("Array.from 类数组转换",function(){var n=Array.from("hello");e(n.join(",")==="h,e,l,l,o","Array.from 字符串");var r=Array.from([1,2,3],function(s){return s*2});e(r.join(",")==="2,4,6","Array.from 带映射函数")}),t("Array.of 创建数组",function(){var n=Array.of(1,2,3);e(n.length===3&&n[0]===1,"Array.of 创建数组"),e(Array.of(7).length===1,"Array.of(7) 和 new Array(7) 不同")}),t("Array.prototype.find / findIndex",function(){var n=[1,2,3,4,5];e(n.find(function(r){return r>3})===4,"find 返回第一个满足条件的元素"),e(n.findIndex(function(r){return r>3})===3,"findIndex 返回第一个满足条件的索引"),e(n.find(function(r){return r>10})===void 0,"find 无匹配返回 undefined")}),t("Array.prototype.fill",function(){var n=[1,2,3,4,5];n.fill(0,2,4),e(n.join(",")==="1,2,0,0,5","fill 局部填充")}),t("Array.prototype.includes",function(){e([1,2,3].includes(2),"includes 存在的元素"),e(![1,2,3].includes(4),"includes 不存在的元素"),e([1,NaN].includes(NaN),"includes 可检测 NaN(indexOf 不行)")}),t("Array.prototype.flat / flatMap",function(){var n=[1,[2,[3,[4]]]];e(n.flat().join(",")==="1,2,3,4","flat 一层"),e(n.flat(1/0).join(",")==="1,2,3,4","flat Infinity 层");var r=[1,2,3].flatMap(function(s){return[s,s*2]});e(r.join(",")==="1,2,2,4,3,6","flatMap")}),t("String.prototype.includes / startsWith / endsWith",function(){var n="Hello, World!";e(n.includes("World"),"includes"),e(n.startsWith("Hello"),"startsWith"),e(n.endsWith("!"),"endsWith"),e(n.startsWith("World",7),"startsWith 从指定位置")}),t("String.prototype.repeat",function(){e("ha".repeat(3)==="hahaha","repeat"),e("".repeat(5)==="","空字符串 repeat")}),t("String.prototype.padStart / padEnd",function(){e("5".padStart(3,"0")==="005","padStart"),e("hi".padEnd(5,".")==="hi...","padEnd"),e("hello".padStart(3)==="hello","长度不足不截断")}),t("String.prototype.trimStart / trimEnd",function(){e(" hello ".trimStart()==="hello ","trimStart"),e(" hello ".trimEnd()===" hello","trimEnd")}),t("Number.isInteger",function(){e(Number.isInteger(42),"42 是整数"),e(!Number.isInteger(42.5),"42.5 不是整数"),e(!Number.isInteger("42"),"字符串不是整数")}),t("Number.isFinite / isNaN",function(){e(Number.isFinite(42),"42 是有限数"),e(!Number.isFinite(1/0),"Infinity 不是有限数"),e(Number.isNaN(NaN),"NaN 是 NaN"),e(!Number.isNaN(42),"42 不是 NaN"),e(!Number.isNaN("NaN"),"字符串 NaN 不触发(与全局 isNaN 不同)")}),t("Number.parseInt / parseFloat",function(){e(Number.parseInt("42px")===42,"Number.parseInt"),e(Number.parseFloat("3.14abc")===3.14,"Number.parseFloat")}),t("Number.EPSILON",function(){var n=.30000000000000004;e(Math.abs(n-.3)<Number.EPSILON,"Number.EPSILON 用于浮点比较")}),t("Number.MAX_SAFE_INTEGER / MIN_SAFE_INTEGER",function(){e(Number.MAX_SAFE_INTEGER===Math.pow(2,53)-1,"MAX_SAFE_INTEGER"),e(Number.isSafeInteger(Number.MAX_SAFE_INTEGER),"isSafeInteger"),e(!Number.isSafeInteger(Number.MAX_SAFE_INTEGER+1),"超出安全整数范围")}),t("Math.sign",function(){e(Math.sign(-5)===-1,"Math.sign 负数"),e(Math.sign(0)===0,"Math.sign 零"),e(Math.sign(5)===1,"Math.sign 正数")}),t("Math.trunc",function(){e(Math.trunc(3.9)===3,"Math.trunc 正数"),e(Math.trunc(-3.9)===-3,"Math.trunc 负数")}),t("Math.cbrt / Math.hypot / Math.log2 / Math.log10",function(){e(Math.cbrt(27)===3,"Math.cbrt 立方根"),e(Math.hypot(3,4)===5,"Math.hypot 斜边"),e(Math.log2(8)===3,"Math.log2"),e(Math.log10(1e3)===3,"Math.log10")}),i()}const _13NewMethods=Object.freeze(Object.defineProperty({__proto__:null,testNewMethods},Symbol.toStringTag,{value:"Module"}));function testModules(){var a=createSuite("模块(Modules)"),t=a.test,e=a.assert,i=a.getResults;return t("命名导出与导入(本工程已在使用)",function(){e(typeof testModules=="function","命名导出的函数可正常被导入调用")}),t("模块作用域独立",function(){var n=new Function("return this")();e(n!==void 0||!0,"模块顶层有独立作用域")}),t("import.meta 可用",function(){e(_typeof({url:_documentCurrentScript&&_documentCurrentScript.tagName.toUpperCase()==="SCRIPT"&&_documentCurrentScript.src||new URL("esfeatures.iife.js",document.baseURI).href})==="object","import.meta 是对象")}),t("动态 import() 返回 Promise",_asyncToGenerator(_regenerator().m(function n(){var r,s;return _regenerator().w(function(o){for(;;)switch(o.n){case 0:return r=Promise.resolve().then(()=>_13NewMethods),e(r instanceof Promise,"动态 import() 返回 Promise"),o.n=1,r;case 1:s=o.v,e(typeof s.testNewMethods=="function","动态导入的模块可正常使用");case 2:return o.a(2)}},n)}))),t("export default 默认导出",function(){e(!0,'默认导出通过 import x from "..." 引入,本工程采用命名导出模式')}),i()}function testBinaryOctalUnicode(){var a=createSuite("进制字面量与Unicode"),t=a.test,e=a.assert,i=a.getResults;return t("二进制字面量 0b",function(){var n=10;e(n===10,"0b1010 应等于十进制 10"),e(!0,"0b11111111 应等于 255")}),t("八进制字面量 0o",function(){var n=15;e(n===15,"0o17 应等于十进制 15"),e(!0,"0o777 应等于 511")}),t("十六进制字面量 0x",function(){e(!0,"0xFF 应等于 255"),e(!0,"0x10 应等于 16")}),t("Number.prototype.toString 进制转换",function(){e(255 .toString(16)==="ff","255 转十六进制"),e(10 .toString(2)==="1010","10 转二进制"),e(15 .toString(8)==="17","15 转八进制")}),t("Unicode 转义 \\uXXXX",function(){var n="♥";e(n==="♥","\\u2665 应为心形符号")}),t("Unicode 码点转义 \\u{XXXXX}",function(){var n="😀";e(n.length===2,"Unicode 超过 FFFF 的字符长度为 2"),e(n.codePointAt(0)===128512,"codePointAt 返回正确码点")}),t("String.fromCodePoint",function(){var n=String.fromCodePoint(128512);e(n.codePointAt(0)===128512,"String.fromCodePoint 与 codePointAt 对应")}),t("字符串 normalize 方法",function(){var n="é",r="é";e(n!==r,"组合与分解形式不直接相等"),e(n===r.normalize("NFC"),"normalize NFC 后相等")}),t("for...of 正确迭代 Unicode 字符",function(){var n="😀A",r=_toConsumableArray(n);e(r.length===2,"for...of 正确按码点迭代")}),i()}function testForOf(){var a=createSuite("for...of 与迭代协议"),t=a.test,e=a.assert,i=a.getResults;return t("for...of 迭代数组",function(){for(var n=[],r=0,s=[1,2,3];r<s.length;r++){var o=s[r];n.push(o)}e(n.join(",")==="1,2,3","for...of 迭代数组")}),t("for...of 迭代字符串",function(){var n=[],r=_createForOfIteratorHelper("abc"),s;try{for(r.s();!(s=r.n()).done;){var o=s.value;n.push(o)}}catch(u){r.e(u)}finally{r.f()}e(n.join("")==="abc","for...of 迭代字符串")}),t("for...of 迭代 Set",function(){var n=[],r=_createForOfIteratorHelper(new Set([1,2,3])),s;try{for(r.s();!(s=r.n()).done;){var o=s.value;n.push(o)}}catch(u){r.e(u)}finally{r.f()}e(n.join(",")==="1,2,3","for...of 迭代 Set")}),t("for...of 迭代 Map",function(){var n=[],r=_createForOfIteratorHelper(new Map([["a",1],["b",2]])),s;try{for(r.s();!(s=r.n()).done;){var o=_slicedToArray(s.value,2),u=o[0],c=o[1];n.push("".concat(u,"=").concat(c))}}catch(f){r.e(f)}finally{r.f()}e(n.join(",")==="a=1,b=2","for...of 迭代 Map")}),t("for...of 迭代 arguments",function(){function n(){var r=[],s=_createForOfIteratorHelper(arguments),o;try{for(s.s();!(o=s.n()).done;){var u=o.value;r.push(u)}}catch(c){s.e(c)}finally{s.f()}return r}e(n(1,2,3).join(",")==="1,2,3","for...of 迭代 arguments")}),i()}function testMapGetOrInsert(){var a=createSuite("map getOrInsert"),t=a.test,e=a.assert,i=a.getResults;return t("getOrInsert - key 已存在返回原值",function(){var n=new Map([["bar","foo"]]),r=n.getOrInsert("bar","default");e(r==="foo","key 已存在应返回原值 foo")}),i()}function testClassFields(){var _createSuite=createSuite("Class Fields (ES2022)"),test=_createSuite.test,assert=_createSuite.assert,getResults=_createSuite.getResults;return test("公共实例字段 —— 声明并初始化",function(){var a=_createClass(function e(i,n){_classCallCheck(this,e),_defineProperty(this,"x",0),_defineProperty(this,"y",0),this.x=i,this.y=n}),t=new a(3,4);assert(t.x===3&&t.y===4,"公共字段应可读写")}),test("公共字段默认值在 constructor 之前初始化",function(){var a=_createClass(function t(){_classCallCheck(this,t),_defineProperty(this,"count",10),this.count+=5});assert(new a().count===15,"默认值应先于 constructor 体初始化")}),test("私有实例字段 #field —— 外部不可访问",function(){var _balance=new WeakMap,BankAccount=function(){function a(){_classCallCheck(this,a),_classPrivateFieldInitSpec(this,_balance,0)}return _createClass(a,[{key:"deposit",value:function(e){_classPrivateFieldSet2(_balance,this,_classPrivateFieldGet2(_balance,this)+e)}},{key:"balance",get:function(){return _classPrivateFieldGet2(_balance,this)}}])}(),acc=new BankAccount;acc.deposit(100),assert(acc.balance===100,"私有字段应通过访问器正确读取"),assert(!("#balance"in acc),"私有字段不应出现在普通属性枚举中");var threw=!1;try{eval("acc.#balance")}catch(a){threw=!0}assert(threw,"外部直接访问私有字段应抛出语法错误")}),test("私有实例方法 #method()",function(){var a=new WeakMap,t=new WeakSet,e=function(){function n(){_classCallCheck(this,n),_classPrivateMethodInitSpec(this,t),_classPrivateFieldInitSpec(this,a,"[LOG]")}return _createClass(n,[{key:"format",value:function(s){return _assertClassBrand(t,this,i).call(this,s)}}])}();function i(n){return"".concat(_classPrivateFieldGet2(a,this)," ").concat(n)}assert(new e().format("hello")==="[LOG] hello","私有方法应正常调用")}),test("静态公共字段",function(){var a=_createClass(function t(){_classCallCheck(this,t)});_defineProperty(a,"version","1.0.0"),_defineProperty(a,"maxRetry",3),assert(a.version==="1.0.0","静态公共字段应可通过类名访问"),assert(a.maxRetry===3,"静态字段应保持初始值")}),test("静态私有字段 —— 追踪实例数量",function(){var a=function(){function e(){var i;_classCallCheck(this,e),t._=(i=t._,i++,i)}return _createClass(e,null,[{key:"getCount",value:function(){return t._}}])}(),t={_:0};new a,new a,new a,assert(a.getCount()===3,"静态私有字段应跨实例共享")}),test("静态私有方法",function(){var a=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"normalize",value:function(n){return t.call(e,n,0,1)}}])}();function t(e,i,n){return Math.min(Math.max(e,i),n)}assert(a.normalize(-.5)===0,"静态私有方法:低于下界应返回 0"),assert(a.normalize(1.5)===1,"静态私有方法:超出上界应返回 1"),assert(a.normalize(.5)===.5,"静态私有方法:正常值应原样返回")}),test("私有字段存在性:`#field in obj`",function(){var a=new WeakMap,t=function(){function e(i){_classCallCheck(this,e),_classPrivateFieldInitSpec(this,a,void 0),_classPrivateFieldSet2(a,this,i)}return _createClass(e,null,[{key:"isNode",value:function(n){return a.has(_checkInRHS(n))}}])}();assert(t.isNode(new t(1))===!0,"实例应包含私有字段"),assert(t.isNode({})===!1,"普通对象不应包含私有字段")}),test("私有字段不参与继承 —— 子类无法访问父类私有字段",function(){var a=new WeakMap,t=function(){function n(r){_classCallCheck(this,n),_classPrivateFieldInitSpec(this,a,void 0),_classPrivateFieldSet2(a,this,r)}return _createClass(n,[{key:"getName",value:function(){return _classPrivateFieldGet2(a,this)}}])}(),e=function(n){function r(){return _classCallCheck(this,r),_callSuper(this,r,arguments)}return _inherits(r,n),_createClass(r,[{key:"bark",value:function(){return"".concat(this.getName()," says woof")}}])}(t),i=new e("Rex");assert(i.bark()==="Rex says woof","子类可通过父类公共方法访问私有字段")}),getResults()}function testClassStaticBlocks(){var a=createSuite("Class Static Blocks (ES2022)"),t=a.test,e=a.assert,i=a.getResults;return t("基本静态块 —— 初始化静态字段",function(){var n,r=_createClass(function s(){_classCallCheck(this,s)});n=r,_defineProperty(r,"host",void 0),_defineProperty(r,"port",void 0),function(){n.host="localhost",n.port=8080}(),e(r.host==="localhost","静态块应初始化 host"),e(r.port===8080,"静态块应初始化 port")}),t("静态块中可使用 try/catch 处理初始化失败",function(){var n,r=_createClass(function s(){_classCallCheck(this,s)});n=r,_defineProperty(r,"value",void 0),function(){try{var s='{"timeout":3000}';n.value=JSON.parse(s).timeout}catch{n.value=1e3}}(),e(r.value===3e3,"静态块中 try/catch 初始化应正确执行")}),t("静态块访问同类私有字段",function(){var n,r=function(){function o(){_classCallCheck(this,o)}return _createClass(o,null,[{key:"getSecret",value:function(){return s._}}])}(),s={_:"initial"};n=function(u){s._=u},n("updated"),e(r.getSecret()==="updated","静态块应能操作同类私有字段")}),t("多个静态块按声明顺序执行",function(){var n,r=[],s=_createClass(function o(){_classCallCheck(this,o)});n=s,_defineProperty(s,"a",void 0),function(){r.push(1),n.a=10}(),_defineProperty(s,"b",void 0),function(){r.push(2),n.b=n.a*2}(),e(r[0]===1&&r[1]===2,"多个静态块应按顺序执行"),e(s.b===20,"第二个静态块应能读取第一个块的结果")}),t("静态块与静态字段声明交替执行",function(){var n=[],r=_createClass(function s(){_classCallCheck(this,s)});_defineProperty(r,"x",(n.push("field-x"),1)),n.push("block-1"),_defineProperty(r,"y",(n.push("field-y"),2)),n.push("block-2"),e(n.join(",")==="field-x,block-1,field-y,block-2","字段与静态块应按声明顺序交替初始化"),e(r.x===1&&r.y===2,"所有字段应正确赋值")}),t("子类静态块在父类之后执行",function(){var n=[];n.push("base"),n.push("child"),e(n[0]==="base"&&n[1]==="child","父类静态块应先于子类执行")}),t("静态块中 this 指向类本身",function(){var n,r=_createClass(function s(){_classCallCheck(this,s)});n=r,_defineProperty(r,"name2","Widget"),_defineProperty(r,"instance",void 0),n.instance={type:n.name2},e(r.instance.type==="Widget","静态块内 this 应指向类本身")}),i()}function testAtMethod(){var a=createSuite("Array/String.at() (ES2022)"),t=a.test,e=a.assert,i=a.getResults;return t("Array.at() —— 正索引与 arr[i] 等价",function(){var n=[10,20,30,40,50];e(n.at(0)===10,"at(0) 应返回第一个元素"),e(n.at(2)===30,"at(2) 应返回第三个元素"),e(n.at(4)===50,"at(4) 应返回最后一个元素")}),t("Array.at() —— 负索引从末尾倒数",function(){var n=[10,20,30,40,50];e(n.at(-1)===50,"at(-1) 应返回最后一个元素"),e(n.at(-2)===40,"at(-2) 应返回倒数第二个元素"),e(n.at(-5)===10,"at(-5) 应返回第一个元素")}),t("Array.at() —— 越界返回 undefined",function(){var n=[1,2,3];e(n.at(5)===void 0,"正向越界应返回 undefined"),e(n.at(-4)===void 0,"负向越界应返回 undefined")}),t("Array.at() —— 空数组始终返回 undefined",function(){e([].at(0)===void 0,"空数组 at(0) 应返回 undefined"),e([].at(-1)===void 0,"空数组 at(-1) 应返回 undefined")}),t("对比旧写法:arr.at(-1) vs arr[arr.length - 1]",function(){var n=[3,1,4,1,5,9,2,6],r=n.at(-1),s=n[n.length-1];e(r===s,"at(-1) 应与 arr[length-1] 等价")}),t("String.at() —— 正索引",function(){var n="hello";e(n.at(0)==="h","at(0) 应返回首字符"),e(n.at(4)==="o","at(4) 应返回末字符")}),t("String.at() —— 负索引",function(){var n="hello";e(n.at(-1)==="o","at(-1) 应返回最后一个字符"),e(n.at(-3)==="l","at(-3) 应返回倒数第三个字符")}),t("String.at() —— 越界返回 undefined",function(){e("abc".at(10)===void 0,"正向越界应返回 undefined"),e("abc".at(-10)===void 0,"负向越界应返回 undefined")}),t("TypedArray.at() —— 支持负索引",function(){var n=new Int32Array([100,200,300,400]);e(n.at(0)===100,"TypedArray.at(0) 应返回第一个元素"),e(n.at(-1)===400,"TypedArray.at(-1) 应返回最后一个元素"),e(n.at(-2)===300,"TypedArray.at(-2) 应返回倒数第二个元素")}),t("at() 不修改原数组",function(){var n=[1,2,3];e(n.length===3&&n[2]===3,"at() 不应修改原数组")}),i()}function testObjectHasOwn(){var a=createSuite("Object.hasOwn() (ES2022)"),t=a.test,e=a.assert,i=a.getResults;return t("基本用法 —— 自有属性返回 true",function(){var n={name:"Alice",age:30};e(Object.hasOwn(n,"name")===!0,"name 是自有属性,应返回 true"),e(Object.hasOwn(n,"age")===!0,"age 是自有属性,应返回 true")}),t("不存在的属性返回 false",function(){var n={a:1};e(Object.hasOwn(n,"b")===!1,"不存在的属性应返回 false"),e(Object.hasOwn(n,"toString")===!1,"原型链上的属性应返回 false")}),t("继承属性返回 false —— 只检查自有属性",function(){var n=_createClass(function o(u){_classCallCheck(this,o),this.name=u}),r=function(o){function u(){return _classCallCheck(this,u),_callSuper(this,u,arguments)}return _inherits(u,o),_createClass(u)}(n),s=new r("Rex");e(Object.hasOwn(s,"name")===!0,"name 是实例自有属性"),e(Object.hasOwn(s,"constructor")===!1,"constructor 在原型上,不是自有属性")}),t("null 原型对象 —— hasOwnProperty 不可用时的安全方案",function(){var n=Object.create(null);n.key="value";var r=!1;try{n.hasOwnProperty("key")}catch{r=!0}e(r,"null 原型对象调用 hasOwnProperty 应抛出错误"),e(Object.hasOwn(n,"key")===!0,"hasOwn 对 null 原型对象应正常工作"),e(Object.hasOwn(n,"other")===!1,"不存在的键应返回 false")}),t("对象覆盖 hasOwnProperty —— hasOwn 不受影响",function(){var n={hasOwnProperty:function(){return!1},secret:42};e(n.hasOwnProperty("secret")===!1,"被覆盖的 hasOwnProperty 返回错误结果"),e(Object.hasOwn(n,"secret")===!0,"hasOwn 不受覆盖影响,结果正确")}),t("值为 undefined 的属性仍返回 true",function(){var n={key:void 0};e(Object.hasOwn(n,"key")===!0,"值为 undefined 的自有属性应返回 true")}),t("Symbol 作为键",function(){var n=Symbol("id"),r=_defineProperty({},n,123);e(Object.hasOwn(r,n)===!0,"Symbol 键的自有属性应返回 true"),e(Object.hasOwn(r,Symbol("id"))===!1,"不同的 Symbol 实例应返回 false")}),t("数组的索引属性",function(){var n=[10,20,30];e(Object.hasOwn(n,0)===!0,"数组索引 0 是自有属性"),e(Object.hasOwn(n,"1")===!0,'字符串索引 "1" 也是自有属性'),e(Object.hasOwn(n,"length")===!0,"length 是数组的自有属性"),e(Object.hasOwn(n,3)===!1,"越界索引应返回 false")}),i()}function testErrorCause(){var a=createSuite("Error Cause (ES2022)"),t=a.test,e=a.assert,i=a.getResults;return t("基本用法 —— cause 属性保存原始错误",function(){var n=new TypeError("原始类型错误"),r=new Error("操作失败",{cause:n});e(r.message==="操作失败","外层错误消息应正确"),e(r.cause===n,"cause 应指向原始错误"),e(r.cause instanceof TypeError,"cause 类型应保留")}),t("所有内置子类均支持 cause",function(){var n=new Error("根因"),r=[new TypeError("类型错误",{cause:n}),new RangeError("范围错误",{cause:n}),new SyntaxError("语法错误",{cause:n})];r.forEach(function(s){e(s.cause===n,"".concat(s.constructor.name," 的 cause 应指向根因"))})}),t("错误链可以多层嵌套",function(){var n=new Error("数据库连接失败"),r=new Error("查询用户失败",{cause:n}),s=new Error("登录接口报错",{cause:r});e(s.cause===r,"第三层 cause 应指向第二层"),e(s.cause.cause===n,"第二层 cause 应指向第一层"),e(s.cause.cause.message==="数据库连接失败","根因消息应可追溯")}),t("不传 cause 时属性为 undefined",function(){var n=new Error("普通错误");e(n.cause===void 0,"未传 cause 时属性应为 undefined")}),t("cause 可以是任意值(不限于 Error)",function(){var n=new Error("原因是字符串",{cause:"网络超时"}),r=new Error("原因是数字",{cause:404}),s=new Error("原因是对象",{cause:{code:"ENOENT"}});e(n.cause==="网络超时","cause 可以是字符串"),e(r.cause===404,"cause 可以是数字"),e(s.cause.code==="ENOENT","cause 可以是对象")}),t("实际应用:fetch 封装中传递原始网络错误",_asyncToGenerator(_regenerator().m(function n(){var r,s,o,u;return _regenerator().w(function(c){for(;;)switch(c.p=c.n){case 0:return s=function(){return s=_asyncToGenerator(_regenerator().m(function l(h){var y;return _regenerator().w(function(p){for(;;)switch(p.p=p.n){case 0:throw p.p=0,new Error("fetch failed: 500");case 1:throw p.p=1,y=p.v,new Error("获取用户 ".concat(h," 失败"),{cause:y});case 2:return p.a(2)}},l,null,[[0,1]])})),s.apply(this,arguments)},r=function(l){return s.apply(this,arguments)},o=null,c.p=1,c.n=2,r(42);case 2:c.n=4;break;case 3:c.p=3,u=c.v,o=u;case 4:e(o!==null,"应捕获到封装后的错误"),e(o.message.includes("42"),"外层错误消息应包含用户 id"),e(o.cause instanceof Error,"cause 应是原始 Error"),e(o.cause.message.includes("500"),"原始错误消息应保留");case 5:return c.a(2)}},n,null,[[1,3]])}))),t("自定义 Error 子类也支持 cause",function(){var n=function(o){function u(c,f){var l;return _classCallCheck(this,u),l=_callSuper(this,u,[c,f]),l.name="AppError",l}return _inherits(u,o),_createClass(u)}(_wrapNativeSuper(Error)),r=new TypeError("底层失败"),s=new n("应用层失败",{cause:r});e(s.name==="AppError","子类名称应正确"),e(s.cause===r,"自定义子类应支持 cause")}),i()}function testRegExpDFlag(){var a=createSuite("RegExp /d flag (ES2022)"),t=a.test,e=a.assert,i=a.getResults,n=function(){try{return new RegExp("x","d").hasIndices===!0}catch{return!1}}();return t("环境支持检测",function(){e(n,"环境不支持 RegExp /d 标志")}),t("hasIndices 属性标识是否启用 /d 标志",function(){if(!n){e(!0,"(跳过:环境不支持 /d 标志)");return}e(new RegExp("x","d").hasIndices===!0,"/d 标志应使 hasIndices 为 true"),e(new RegExp("x").hasIndices===!1,"无 /d 标志时 hasIndices 应为 false")}),t("整体匹配位置 indices[0]",function(){if(!n){e(!0,"(跳过)");return}var r="hello world".match(new RegExp("world","d"));e(Array.isArray(r.indices),"结果应包含 indices 数组"),e(r.indices[0][0]===6,"匹配起始位置应为 6"),e(r.indices[0][1]===11,"匹配结束位置应为 11(不含)"),e("hello world".slice(6,11)==="world","slice 切出来应等于匹配内容")}),t("捕获组位置 indices[n]",function(){if(!n){e(!0,"(跳过)");return}var r=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})","d"),s="日期:2025-06-15".match(r);e(s.indices[1][0]===3&&s.indices[1][1]===7,"年份捕获组位置应为 [3,7]"),e(s.indices[2][0]===8&&s.indices[2][1]===10,"月份捕获组位置应为 [8,10]"),e(s.indices[3][0]===11&&s.indices[3][1]===13,"日期捕获组位置应为 [11,13]")}),t("通过 indices 验证 slice 还原捕获组内容",function(){if(!n){e(!0,"(跳过)");return}var r="姓名:Alice,年龄:30",s=new RegExp("姓名:(\\w+),年龄:(\\d+)","d"),o=r.match(s),u=_slicedToArray(o.indices[1],2),c=u[0],f=u[1],l=_slicedToArray(o.indices[2],2),h=l[0],y=l[1];e(r.slice(c,f)==="Alice","通过 indices 切出的姓名应为 Alice"),e(r.slice(h,y)==="30","通过 indices 切出的年龄应为 30")}),t("具名捕获组的位置 indices.groups",function(){var r,s;if(!n){e(!0,"(跳过)");return}var o=_wrapRegExp(new RegExp("(\\d{4})-(\\d{2})","d"),{year:1,month:2}),u="发布于 2025-06".match(o);e(u.indices.groups!==void 0,"具名组应出现在 indices.groups 中");var c=u.indices.groups,f=c.year,l=c.month;e((r="发布于 2025-06").slice.apply(r,_toConsumableArray(f))==="2025","具名组 year 位置应正确"),e((s="发布于 2025-06").slice.apply(s,_toConsumableArray(l))==="06","具名组 month 位置应正确")}),t("未匹配的可选组 indices 为 undefined",function(){if(!n){e(!0,"(跳过)");return}var r=new RegExp("(a)?(b)","d"),s="b".match(r);e(s.indices[1]===void 0,"未参与匹配的可选组 indices 应为 undefined"),e(Array.isArray(s.indices[2]),"已匹配的组 indices 应为数组")}),t("/d 与 /g 组合 —— exec 每次返回带 indices 的结果",function(){if(!n){e(!0,"(跳过)");return}for(var r=new RegExp("\\d+","dg"),s="a1b22c333",o=[],u;(u=r.exec(s))!==null;)o.push(u.indices[0]);e(o.length===3,"应匹配到 3 个数字"),e(o[0][0]===1,"第一个数字起始位置应为 1"),e(o[1][0]===3,"第二个数字起始位置应为 3"),e(o[2][0]===6,"第三个数字起始位置应为 6")}),i()}function testTopLevelAwait(){return _testTopLevelAwait.apply(this,arguments)}function _testTopLevelAwait(){return _testTopLevelAwait=_asyncToGenerator(_regenerator().m(function a(){var t,e,i,n;return _regenerator().w(function(r){for(;;)switch(r.n){case 0:return t=createSuite("Top-level await (ES2022)"),e=t.test,i=t.assert,n=t.getResults,r.n=1,e("async 函数内的 await 是等价基础能力",_asyncToGenerator(_regenerator().m(function s(){var o;return _regenerator().w(function(u){for(;;)switch(u.n){case 0:return u.n=1,Promise.resolve(42);case 1:o=u.v,i(o===42,"await 在 async 函数顶层应正常工作");case 2:return u.a(2)}},s)})));case 1:return r.n=2,e("await 可以等待动态 import()",_asyncToGenerator(_regenerator().m(function s(){var o,u;return _regenerator().w(function(c){for(;;)switch(c.n){case 0:return o=function(){return Promise.resolve({default:"module-content",util:function(){return"ok"}})},c.n=1,o();case 1:u=c.v,i(u.default==="module-content","await 动态导入应返回模块内容"),i(u.util()==="ok","模块导出的函数应可调用");case 2:return c.a(2)}},s)})));case 2:return r.n=3,e("await 保序 —— 导入方等待模块初始化完成",_asyncToGenerator(_regenerator().m(function s(){var o,u;return _regenerator().w(function(c){for(;;)switch(c.n){case 0:return o=[],c.n=1,_asyncToGenerator(_regenerator().m(function f(){return _regenerator().w(function(l){for(;;)switch(l.n){case 0:return o.push("A:start"),l.n=1,new Promise(function(h){return setTimeout(h,0)});case 1:return o.push("A:ready"),l.a(2,{data:"initialized"})}},f)}))();case 1:u=c.v,o.push("B:use"),i(u.data==="initialized","模块 A 初始化完成后才能被使用"),i(o.join(",")==="A:start,A:ready,B:use","执行顺序应严格保序");case 2:return c.a(2)}},s)})));case 3:return r.n=4,e("await 与条件导入模拟",_asyncToGenerator(_regenerator().m(function s(){var o,u;return _regenerator().w(function(c){for(;;)switch(c.n){case 0:return o=typeof window<"u",c.n=1,Promise.resolve(o?"browser":"node");case 1:u=c.v,i(typeof u=="string","条件 await 应返回字符串平台标识"),i(u==="browser"||u==="node","平台标识应为 browser 或 node");case 2:return c.a(2)}},s)})));case 4:return r.n=5,e("await 错误应在模块加载阶段被捕获",_asyncToGenerator(_regenerator().m(function s(){var o,u;return _regenerator().w(function(c){for(;;)switch(c.p=c.n){case 0:return o=null,c.p=1,c.n=2,Promise.reject(new Error("模块初始化失败"));case 2:c.n=4;break;case 3:c.p=3,u=c.v,o=u;case 4:i(o instanceof Error,"应捕获到 Error"),i(o.message==="模块初始化失败","错误消息应正确传递");case 5:return c.a(2)}},s,null,[[1,3]])})));case 5:return r.n=6,e("await 不阻塞无依赖的兄弟模块(并行加载)",_asyncToGenerator(_regenerator().m(function s(){var o,u,c,f,l,h;return _regenerator().w(function(y){for(;;)switch(y.n){case 0:return o=Date.now(),y.n=1,Promise.all([new Promise(function(p){return setTimeout(function(){return p("A")},10)}),new Promise(function(p){return setTimeout(function(){return p("B")},10)})]);case 1:u=y.v,c=_slicedToArray(u,2),f=c[0],l=c[1],h=Date.now()-o,i(f==="A"&&l==="B","并行 await 两个模块都应成功完成"),i(h<50,"并行执行耗时应远小于串行(~10ms vs ~20ms)");case 2:return y.a(2)}},s)})));case 6:return r.a(2,n())}},a)})),_testTopLevelAwait.apply(this,arguments)}function testIteratorHelpers(){var a=createSuite("Iterator Helpers (ES2025)"),t=a.test,e=a.assert,i=a.getResults,n=typeof Iterator<"u"&&typeof Iterator.from=="function";return t("环境支持检测",function(){e(n,"环境不支持 Iterator Helpers")}),t("Iterator.from() 将可迭代对象转为迭代器",function(){if(!n){e(!0,"(跳过:环境不支持 Iterator.from)");return}var r=Iterator.from([1,2,3]);e(typeof r.next=="function","应返回迭代器对象")}),t(".map() 惰性映射",function(){if(!n){e(!0,"(跳过)");return}var r=Iterator.from([1,2,3]).map(function(s){return s*2}).toArray();e(r.length===3&&r[0]===2&&r[2]===6,"map 结果应为 [2,4,6]")}),t(".filter() 惰性过滤",function(){if(!n){e(!0,"(跳过)");return}var r=Iterator.from([1,2,3,4,5]).filter(function(s){return s%2===0}).toArray();e(r.length===2&&r[0]===2&&r[1]===4,"filter 结果应为 [2,4]")}),t(".take(n) 取前 n 个元素",function(){if(!n){e(!0,"(跳过)");return}var r=Iterator.from([10,20,30,40,50]).take(3).toArray();e(r.length===3&&r[2]===30,"take(3) 应只取前 3 个")}),t(".drop(n) 跳过前 n 个元素",function(){if(!n){e(!0,"(跳过)");return}var r=Iterator.from([1,2,3,4,5]).drop(2).toArray();e(r.length===3&&r[0]===3,"drop(2) 应从第 3 个开始")}),t(".flatMap() 平铺映射",function(){if(!n){e(!0,"(跳过)");return}var r=Iterator.from([1,2,3]).flatMap(function(s){return[s,s*10]}).toArray();e(r.length===6&&r[1]===10&&r[3]===20,"flatMap 应正确展开")}),t(".reduce() 归约",function(){if(!n){e(!0,"(跳过)");return}var r=Iterator.from([1,2,3,4]).reduce(function(s,o){return s+o},0);e(r===10,"reduce 求和应为 10")}),t(".toArray() 转为数组",function(){if(!n){e(!0,"(跳过)");return}var r=Iterator.from(new Set([7,8,9])).toArray();e(Array.isArray(r)&&r.length===3,"toArray 应返回普通数组")}),t(".forEach() 遍历副作用",function(){if(!n){e(!0,"(跳过)");return}var r=[];Iterator.from(["a","b","c"]).forEach(function(s){return r.push(s)}),e(r.join("")==="abc","forEach 应依次访问每个元素")}),t(".some() / .every() 短路判断",function(){if(!n){e(!0,"(跳过)");return}var r=Iterator.from([1,3,4,5]).some(function(o){return o%2===0}),s=Iterator.from([1,2,3]).every(function(o){return o>0});e(r===!0&&s===!0,"some/every 应正确短路求值")}),t(".find() 查找第一个匹配元素",function(){if(!n){e(!0,"(跳过)");return}var r=Iterator.from([1,3,5,6,7]).find(function(s){return s%2===0});e(r===6,"find 应返回第一个偶数 6")}),t("链式调用:map + filter + take",function(){if(!n){e(!0,"(跳过)");return}var r=Iterator.from([1,2,3,4,5,6,7,8]).map(function(s){return s*s}).filter(function(s){return s>10}).take(3).toArray();e(r.length===3&&r[0]===16&&r[2]===36,"链式调用结果应为 [16,25,36]")}),i()}function testSetMethods(){var a=createSuite("New Set Methods (ES2025)"),t=a.test,e=a.assert,i=a.getResults,n=typeof Set.prototype.union=="function";return t("环境支持检测",function(){e(n,"环境不支持 Set 新方法(union/intersection 等)")}),t("union() —— 并集",function(){if(!n){e(!0,"(跳过:环境不支持 Set.prototype.union)");return}var r=new Set([1,2,3]),s=new Set([3,4,5]),o=r.union(s);e(o.size===5&&o.has(1)&&o.has(5),"并集应包含两个集合所有元素")}),t("intersection() —— 交集",function(){if(!n){e(!0,"(跳过)");return}var r=new Set([1,2,3,4]),s=new Set([3,4,5,6]),o=r.intersection(s);e(o.size===2&&o.has(3)&&o.has(4),"交集应只含共同元素 3,4")}),t("difference() —— 差集(A - B)",function(){if(!n){e(!0,"(跳过)");return}var r=new Set([1,2,3,4]),s=new Set([3,4,5]),o=r.difference(s);e(o.size===2&&o.has(1)&&o.has(2)&&!o.has(3),"差集应为 {1,2}")}),t("symmetricDifference() —— 对称差集",function(){if(!n){e(!0,"(跳过)");return}var r=new Set([1,2,3]),s=new Set([2,3,4]),o=r.symmetricDifference(s);e(o.size===2&&o.has(1)&&o.has(4),"对称差集应为 {1,4}")}),t("isSubsetOf() —— 子集判断",function(){if(!n){e(!0,"(跳过)");return}var r=new Set([2,3]),s=new Set([1,2,3,4]);e(r.isSubsetOf(s)===!0,"a ⊆ b 应为 true"),e(s.isSubsetOf(r)===!1,"b ⊆ a 应为 false")}),t("isSupersetOf() —— 超集判断",function(){if(!n){e(!0,"(跳过)");return}var r=new Set([1,2,3,4]),s=new Set([2,3]);e(r.isSupersetOf(s)===!0,"a ⊇ b 应为 true"),e(s.isSupersetOf(r)===!1,"b ⊇ a 应为 false")}),t("isDisjointFrom() —— 不相交判断",function(){if(!n){e(!0,"(跳过)");return}var r=new Set([1,2]),s=new Set([3,4]),o=new Set([2,5]);e(r.isDisjointFrom(s)===!0,"a 与 b 无交集,应为 true"),e(r.isDisjointFrom(o)===!1,"a 与 c 有交集 2,应为 false")}),t("方法返回新 Set,不修改原集合",function(){if(!n){e(!0,"(跳过)");return}var r=new Set([1,2,3]),s=new Set([3,4]),o=r.union(s);e(r.size===3&&s.size===2,"原集合不应被修改"),e(o!==r&&o!==s,"应返回全新的 Set 实例")}),t("接受任意可迭代对象(不限于 Set)",function(){if(!n){e(!0,"(跳过)");return}var r=new Set([1,2,3]),s=r.intersection(new Set([2,3,4]));e(s.size===2&&s.has(2)&&s.has(3),"应支持传入普通数组")}),i()}function testPromiseTry(){return _testPromiseTry.apply(this,arguments)}function _testPromiseTry(){return _testPromiseTry=_asyncToGenerator(_regenerator().m(function a(){var t,e,i,n,r;return _regenerator().w(function(s){for(;;)switch(s.n){case 0:return t=createSuite("Promise.try (ES2025)"),e=t.test,i=t.assert,n=t.getResults,r=typeof Promise.try=="function",s.n=1,e("环境支持检测",_asyncToGenerator(_regenerator().m(function o(){return _regenerator().w(function(u){for(;;)switch(u.n){case 0:if(r){u.n=1;break}return i(!1,"(环境不支持 Promise.try)"),u.a(2);case 1:i(!0,"环境支持 Promise.try");case 2:return u.a(2)}},o)})));case 1:return s.n=2,e("同步函数 —— 返回值转为 resolved",_asyncToGenerator(_regenerator().m(function o(){var u;return _regenerator().w(function(c){for(;;)switch(c.n){case 0:if(r){c.n=1;break}return i(!0,"(跳过:环境不支持 Promise.try)"),c.a(2);case 1:return c.n=2,Promise.try(function(){return 42});case 2:u=c.v,i(u===42,"同步返回值应被 resolve 为 42");case 3:return c.a(2)}},o)})));case 2:return s.n=3,e("同步函数 —— 抛出异常转为 rejected",_asyncToGenerator(_regenerator().m(function o(){var u;return _regenerator().w(function(c){for(;;)switch(c.n){case 0:if(r){c.n=1;break}return i(!0,"(跳过)"),c.a(2);case 1:return u=null,c.n=2,Promise.try(function(){throw new Error("同步错误")}).catch(function(f){u=f});case 2:i(u instanceof Error&&u.message==="同步错误","同步异常应转为 rejected");case 3:return c.a(2)}},o)})));case 3:return s.n=4,e("异步函数 —— resolved 正常透传",_asyncToGenerator(_regenerator().m(function o(){var u;return _regenerator().w(function(c){for(;;)switch(c.n){case 0:if(r){c.n=1;break}return i(!0,"(跳过)"),c.a(2);case 1:return c.n=2,Promise.try(_asyncToGenerator(_regenerator().m(function f(){return _regenerator().w(function(l){for(;;)switch(l.n){case 0:return l.a(2,"async result")}},f)})));case 2:u=c.v,i(u==="async result","异步 resolved 值应透传");case 3:return c.a(2)}},o)})));case 4:return s.n=5,e("异步函数 —— rejected 正常透传",_asyncToGenerator(_regenerator().m(function o(){var u;return _regenerator().w(function(c){for(;;)switch(c.n){case 0:if(r){c.n=1;break}return i(!0,"(跳过)"),c.a(2);case 1:return u=null,c.n=2,Promise.try(_asyncToGenerator(_regenerator().m(function f(){return _regenerator().w(function(l){for(;;)switch(l.n){case 0:throw new Error("异步错误");case 1:return l.a(2)}},f)}))).catch(function(f){u=f});case 2:i(u instanceof Error&&u.message==="异步错误","异步 rejected 应透传");case 3:return c.a(2)}},o)})));case 5:return s.n=6,e("返回已有 Promise —— 直接透传",_asyncToGenerator(_regenerator().m(function o(){var u,c;return _regenerator().w(function(f){for(;;)switch(f.n){case 0:if(r){f.n=1;break}return i(!0,"(跳过)"),f.a(2);case 1:return u=Promise.resolve("original"),f.n=2,Promise.try(function(){return u});case 2:c=f.v,i(c==="original","返回已有 Promise 的值应直接透传");case 3:return f.a(2)}},o)})));case 6:return s.n=7,e("传递参数给回调函数",_asyncToGenerator(_regenerator().m(function o(){var u;return _regenerator().w(function(c){for(;;)switch(c.n){case 0:if(r){c.n=1;break}return i(!0,"(跳过)"),c.a(2);case 1:return c.n=2,Promise.try(function(f,l){return f+l},10,20);case 2:u=c.v,i(u===30,"应能向回调函数传递参数");case 3:return c.a(2)}},o)})));case 7:return s.n=8,e("对比 new Promise —— 捕获同步异常的等价写法",_asyncToGenerator(_regenerator().m(function o(){var u,c,f,l,h,y;return _regenerator().w(function(p){for(;;)switch(p.n){case 0:if(r){p.n=1;break}return i(!0,"(跳过)"),p.a(2);case 1:return u=new Promise(function(S){return S(JSON.parse('{"key":"value"}'))}),c=Promise.try(function(){return JSON.parse('{"key":"value"}')}),p.n=2,Promise.all([u,c]);case 2:f=p.v,l=_slicedToArray(f,2),h=l[0],y=l[1],i(h.key==="value"&&y.key==="value","两种写法结果应一致");case 3:return p.a(2)}},o)})));case 8:return s.a(2,n())}},a)})),_testPromiseTry.apply(this,arguments)}function testRegExpDuplicateGroups(){var a=createSuite("RegExp Duplicate Named Capture Groups (ES2025)"),t=a.test,e=a.assert,i=a.getResults,n=!1;try{new RegExp("(?<a>x)|(?<a>y)"),n=!0}catch{n=!1}return t("环境支持检测",function(){e(n,"环境不支持重复命名捕获组")}),t("同一命名组在不同分支中可重复使用",function(){if(!n){e(!0,"(跳过:环境不支持重复命名捕获组)");return}var r=_wrapRegExp(/(\d{4})-(\d{2})-(\d{2})|(\d{2})\/(\d{2})\/(\d{4})/,{year:[1,6],month:[2,5],day:[3,4]}),s="2025-06-15".match(r),o="15/06/2025".match(r);e(s.groups.year==="2025"&&s.groups.month==="06","格式一:年月应正确解析"),e(o.groups.year==="2025"&&o.groups.month==="06","格式二:年月应正确解析")}),t("同名组只有命中的那个分支有值,另一个为 undefined",function(){if(!n){e(!0,"(跳过)");return}var r=_wrapRegExp(/([A-Z]+)|(\d+)/,{val:[1,2]}),s="ABC".match(r),o="123".match(r);e(s.groups.val==="ABC",'字母分支命中时 val 应为 "ABC"'),e(o.groups.val==="123",'数字分支命中时 val 应为 "123"')}),t("与 String.prototype.replace 命名引用配合使用",function(){if(!n){e(!0,"(跳过)");return}var r=_wrapRegExp(/(\d{4})-(\d{2})-(\d{2})|(\d{2})\/(\d{2})\/(\d{4})/,{y:[1,6],m:[2,4],d:[3,5]}),s="2025-06-15".replace(r,"$<y>/$<m>/$<d>"),o="06/15/2025".replace(r,"$<y>/$<m>/$<d>");e(s==="2025/06/15","格式一替换应得 2025/06/15"),e(o==="2025/06/15","格式二替换应得 2025/06/15")}),t("matchAll 中重复命名组也正常工作",function(){if(!n){e(!0,"(跳过)");return}var r=_wrapRegExp(/([a-z]+)|(\d+)/g,{word:[1,2]}),s=_toConsumableArray("hello 42 world 7".matchAll(r)),o=s.map(function(u){return u.groups.word});e(o.length===4&&o[0]==="hello"&&o[1]==="42","matchAll 应正确提取所有命中词")}),t("非命中分支的同名组值为 undefined",function(){if(!n){e(!0,"(跳过)");return}var r=_wrapRegExp(/(foo)|(bar)/,{a:[1,2]}),s="bar".match(r);e(s.groups.a==="bar","应取命中分支的值")}),i()}function testUint8ArrayBase64Hex(){var a=createSuite("Uint8Array Base64/Hex (ES2025)"),t=a.test,e=a.assert,i=a.getResults,n=typeof Uint8Array.prototype.toBase64=="function";return t("环境支持检测",function(){e(n,"环境不支持 Uint8Array Base64/Hex 方法")}),t("toBase64() —— Uint8Array 转 Base64 字符串",function(){if(!n){e(!0,"(跳过:环境不支持 Uint8Array.toBase64)");return}var r=new Uint8Array([72,101,108,108,111]),s=r.toBase64();e(s==="SGVsbG8=",'toBase64 应返回 "SGVsbG8=",实际: '.concat(s))}),t("fromBase64() —— Base64 字符串转 Uint8Array",function(){if(!n){e(!0,"(跳过)");return}var r=Uint8Array.fromBase64("SGVsbG8=");e(r.length===5&&r[0]===72&&r[4]===111,"fromBase64 应还原为正确字节")}),t("toHex() —— Uint8Array 转十六进制字符串",function(){if(!n){e(!0,"(跳过)");return}var r=new Uint8Array([222,173,190,239]),s=r.toHex();e(s==="deadbeef",'toHex 应返回 "deadbeef",实际: '.concat(s))}),t("fromHex() —— 十六进制字符串转 Uint8Array",function(){if(!n){e(!0,"(跳过)");return}var r=Uint8Array.fromHex("deadbeef");e(r.length===4&&r[0]===222&&r[3]===239,"fromHex 应正确还原字节")}),t("Base64 round-trip(互转验证)",function(){if(!n){e(!0,"(跳过)");return}var r=new Uint8Array([1,2,3,255,0,128]),s=Uint8Array.fromBase64(r.toBase64());e(r.length===s.length&&r.every(function(o,u){return o===s[u]}),"Base64 round-trip 应完全还原原始字节")}),t("Hex round-trip(互转验证)",function(){if(!n){e(!0,"(跳过)");return}var r=new Uint8Array([0,127,128,255]),s=Uint8Array.fromHex(r.toHex());e(r.length===s.length&&r.every(function(o,u){return o===s[u]}),"Hex round-trip 应完全还原原始字节")}),t("空数组 toBase64 返回空字符串",function(){if(!n){e(!0,"(跳过)");return}var r=new Uint8Array([]);e(r.toBase64()==="","空 Uint8Array 的 Base64 应为空字符串")}),t("空字符串 fromHex 返回空 Uint8Array",function(){if(!n){e(!0,"(跳过)");return}var r=Uint8Array.fromHex("");e(r.length===0,"空字符串 fromHex 应返回空 Uint8Array")}),t("toBase64 支持 URL-safe 模式",function(){if(!n){e(!0,"(跳过)");return}var r=new Uint8Array([251,255]),s=r.toBase64(),o=r.toBase64({alphabet:"base64url"});e(o.indexOf("+")===-1&&o.indexOf("/")===-1,"URL-safe Base64 不应含 + 或 /"),e(s!==o||!s.includes("+")&&!s.includes("/"),"URL-safe 与标准编码结果应存在差异(或均不含特殊字符)")}),i()}function testJsonParseSource(){var a=createSuite("JSON.parse Source Text Access (ES2025)"),t=a.test,e=a.assert,i=a.getResults,n=!1;try{JSON.parse("1",function(r,s,o){return o&&typeof o.source=="string"&&(n=!0),s})}catch{}return t("环境支持检测",function(){e(n,"环境不支持 JSON.parse source text access")}),t("reviver 接收第三个参数 context",function(){if(!n){e(!0,"(跳过:环境不支持 JSON.parse source text access)");return}var r=null;JSON.parse('"hello"',function(s,o,u){return s===""&&(r=u),o}),e(r!==null&&typeof r.source=="string","reviver 应收到含 source 属性的 context 对象")}),t("context.source 为该值的原始 JSON 文本",function(){if(!n){e(!0,"(跳过)");return}var r={};JSON.parse('{"a": 42, "b": "hello"}',function(s,o,u){return s!==""&&(r[s]=u.source),o}),e(r.a==="42",'数字的 source 应为 "42",实际: "'.concat(r.a,'"')),e(r.b==='"hello"',`字符串的 source 应为 '"hello"',实际: "`.concat(r.b,'"'))}),t("利用 source 精确解析超大整数(BigInt)",function(){if(!n){e(!0,"(跳过)");return}var r="9007199254740993",s=JSON.parse('{"id":'.concat(r,"}"),function(o,u,c){return o===""?u:/^\d+$/.test(c.source)?BigInt(c.source):u});e(typeof s.id=="bigint","超大整数应被转为 BigInt"),e(s.id===BigInt(r),"BigInt 值应精确等于 ".concat(r))}),t("嵌套对象中每个值都能获取自己的 source",function(){if(!n){e(!0,"(跳过)");return}var r=[];JSON.parse('{"x":1,"arr":[2,3]}',function(s,o,u){return s!==""&&r.push(u.source),o}),e(r.includes("1")&&r.includes("2")&&r.includes("3"),"嵌套结构中每个原始值都应能取到 source")}),t("null / boolean 也有对应 source",function(){if(!n){e(!0,"(跳过)");return}var r={};JSON.parse('{"a":null,"b":true,"c":false}',function(s,o,u){return s!==""&&(r[s]=u.source),o}),e(r.a==="null"&&r.b==="true"&&r.c==="false","null/true/false 的 source 应为对应的原始文本")}),i()}function testErrorIsError(){var a=createSuite("Error.isError (ES2025)"),t=a.test,e=a.assert,i=a.getResults,n=typeof Error.isError=="function";return t("环境支持检测",function(){e(n,"环境不支持 Error.isError")}),t("原生 Error 实例返回 true",function(){if(!n){e(!0,"(跳过:环境不支持 Error.isError)");return}e(Error.isError(new Error("test"))===!0,"new Error() 应返回 true")}),t("Error 子类实例返回 true",function(){if(!n){e(!0,"(跳过)");return}e(Error.isError(new TypeError("type"))===!0,"TypeError 应返回 true"),e(Error.isError(new RangeError("range"))===!0,"RangeError 应返回 true"),e(Error.isError(new SyntaxError("syntax"))===!0,"SyntaxError 应返回 true"),e(Error.isError(new ReferenceError("ref"))===!0,"ReferenceError 应返回 true"),e(Error.isError(new URIError("uri"))===!0,"URIError 应返回 true"),e(Error.isError(new EvalError("eval"))===!0,"EvalError 应返回 true")}),t("自定义 Error 子类实例返回 true",function(){if(!n){e(!0,"(跳过)");return}var r=function(s){function o(u){var c;return _classCallCheck(this,o),c=_callSuper(this,o,[u]),c.name="AppError",c}return _inherits(o,s),_createClass(o)}(_wrapNativeSuper(Error));e(Error.isError(new r("app"))===!0,"自定义 Error 子类应返回 true")}),t("普通对象返回 false",function(){if(!n){e(!0,"(跳过)");return}e(Error.isError({})===!1,"普通对象应返回 false"),e(Error.isError({message:"fake",stack:""})===!1,"伪造 Error 对象应返回 false")}),t("模拟 Error 对象(纯 JS 构造)返回 false",function(){if(!n){e(!0,"(跳过)");return}var r=Object.create(Error.prototype);r.message="fake",e(Error.isError(null)===!1,"null 应返回 false"),e(Error.isError(void 0)===!1,"undefined 应返回 false"),e(Error.isError(42)===!1,"数字应返回 false"),e(Error.isError("error")===!1,'字符串 "error" 应返回 false')}),t("数组、函数、正则等非 Error 值返回 false",function(){if(!n){e(!0,"(跳过)");return}e(Error.isError([])===!1,"数组应返回 false"),e(Error.isError(function(){})===!1,"函数应返回 false"),e(Error.isError(/regex/)===!1,"正则应返回 false"),e(Error.isError(new Date)===!1,"Date 应返回 false")}),t("实际使用场景:统一捕获并判断 catch 的值",function(){if(!n){e(!0,"(跳过)");return}function r(o){if(o)throw new TypeError("类型错误");return Promise.reject("string rejection")}var s=null;try{r(!0)}catch(o){s=o}e(Error.isError(s)===!0,"try/catch 捕获的 Error 应识别为 true"),e(Error.isError("string rejection")===!1,"字符串 rejection 应识别为 false")}),i()}function testFloat16Array(){var a=createSuite("Float16Array (ES2025)"),t=a.test,e=a.assert,i=a.getResults,n=typeof Float16Array<"u";return t("环境支持检测",function(){e(n,"环境不支持 Float16Array")}),t("Float16Array 可正常创建",function(){if(!n){e(!0,"(跳过:环境不支持 Float16Array)");return}var r=new Float16Array(4);e(r.length===4,"Float16Array 长度应为 4"),e(r.BYTES_PER_ELEMENT===2,"每个元素应占 2 字节(16 位)")}),t("从数组初始化并读取值",function(){if(!n){e(!0,"(跳过)");return}var r=new Float16Array([1,.5,-1,0]);e(r[0]===1,"arr[0] 应为 1.0"),e(r[1]===.5,"arr[1] 应为 0.5"),e(r[2]===-1,"arr[2] 应为 -1.0"),e(r[3]===0,"arr[3] 应为 0.0")}),t("Math.f16round() 舍入到最近 float16 值",function(){if(typeof Math.f16round!="function"){e(!0,"(跳过:环境不支持 Math.f16round)");return}var r=Math.f16round(1.337);e(typeof r=="number","Math.f16round 应返回数字"),e(Math.abs(r-1.337)<.01,"舍入误差应在 0.01 以内"),e(r!==1.337,"应发生精度损失,结果不等于输入值")}),t("Math.f16round(Infinity) / (-Infinity) / NaN 特殊值",function(){if(typeof Math.f16round!="function"){e(!0,"(跳过)");return}e(Math.f16round(1/0)===1/0,"Infinity 应保持不变"),e(Math.f16round(-1/0)===-1/0,"-Infinity 应保持不变"),e(Number.isNaN(Math.f16round(NaN)),"NaN 应保持 NaN"),e(Math.f16round(0)===0,"0 应保持 0")}),t("DataView.getFloat16 / setFloat16",function(){if(!n){e(!0,"(跳过)");return}var r=new DataView(new ArrayBuffer(4));if(typeof r.setFloat16!="function"){e(!0,"(跳过:DataView 不支持 float16)");return}r.setFloat16(0,1.5,!0);var s=r.getFloat16(0,!0);e(s===1.5,"DataView setFloat16/getFloat16 round-trip 应还原 1.5")}),t("Float16Array 支持 TypedArray 通用方法",function(){if(!n){e(!0,"(跳过)");return}var r=new Float16Array([3,1,4,1,5]);r.sort(),e(r[0]===1&&r[4]===5,"sort 后最小值应为 1,最大值应为 5");var s=r.map(function(o){return o*2});e(s instanceof Float16Array,"map 应返回 Float16Array")}),t("Float16Array 内存占用是 Float32Array 的一半",function(){if(!n){e(!0,"(跳过)");return}var r=100,s=new Float16Array(r),o=new Float32Array(r);e(s.byteLength===o.byteLength/2,"Float16Array 字节长度应是 Float32Array 的一半")}),i()}function testMathSumPrecise(){var a=createSuite("Math.sumPrecise() (ES2026)"),t=a.test,e=a.assert,i=a.getResults,n=typeof Math.sumPrecise=="function";return t("环境支持检测",function(){e(n,"环境不支持 Math.sumPrecise")}),t("基本求和 —— 整数",function(){if(!n){e(!0,"(跳过:环境不支持 Math.sumPrecise)");return}e(Math.sumPrecise([1,2,3,4,5])===15,"整数求和应为 15"),e(Math.sumPrecise([])===0,"空数组求和应为 0"),e(Math.sumPrecise([42])===42,"单元素求和应为自身")}),t("精确处理浮点数累积误差",function(){if(!n){e(!0,"(跳过)");return}var r=[.1,.2,.3].reduce(function(o,u){return o+u}),s=Math.sumPrecise([.1,.2,.3]);e(r!==.6,"普通 reduce 应存在浮点误差(验证前提)"),e(s===.6,"Math.sumPrecise 应精确返回 0.6")}),t("大量小数精确求和",function(){if(!n){e(!0,"(跳过)");return}var r=1/3,s=Math.sumPrecise([r,r,r]);e(typeof s=="number","应返回数值类型"),e(s>.999&&s<=1,"三个 1/3 之和应尽量接近 1")}),t("接受任意可迭代对象",function(){var r=_regenerator().m(o);if(!n){e(!0,"(跳过)");return}var s=Math.sumPrecise(new Set([10,20,30]));e(s===60,"支持 Set 可迭代对象");function o(){return _regenerator().w(function(c){for(;;)switch(c.n){case 0:return c.n=1,1;case 1:return c.n=2,2;case 2:return c.n=3,3;case 3:return c.a(2)}},r)}var u=Math.sumPrecise(o());e(u===6,"支持 Generator 可迭代对象")}),t("特殊值处理",function(){if(!n){e(!0,"(跳过)");return}e(Math.sumPrecise([0])===0,"+0 求和应为 0"),e(Math.sumPrecise([-0])===0,"-0 求和应为 0(结果为 +0)"),e(Math.sumPrecise([1,1/0])===1/0,"含 Infinity 结果应为 Infinity"),e(Math.sumPrecise([-1/0,1])===-1/0,"含 -Infinity 结果应为 -Infinity"),e(Number.isNaN(Math.sumPrecise([1/0,-1/0])),"Inf + (-Inf) 应为 NaN"),e(Number.isNaN(Math.sumPrecise([1,NaN,3])),"含 NaN 结果应为 NaN")}),t("非数值元素应抛出 TypeError",function(){if(!n){e(!0,"(跳过)");return}var r=!1;try{Math.sumPrecise([1,"2",3])}catch(s){r=s instanceof TypeError}e(r,"非数值元素应抛出 TypeError")}),i()}function testRegExpEscape(){var a=createSuite("RegExp.escape() (ES2026)"),t=a.test,e=a.assert,i=a.getResults,n=typeof RegExp.escape=="function";return t("环境支持检测",function(){e(n,"环境不支持 RegExp.escape")}),t("转义正则特殊字符",function(){if(!n){e(!0,"(跳过:环境不支持 RegExp.escape)");return}var r="^$.*+?()[]{}|\\",s=RegExp.escape(r);e(typeof s=="string","应返回字符串"),e(s.includes("\\^"),"^ 应被转义"),e(s.includes("\\$"),"$ 应被转义"),e(s.includes("\\."),". 应被转义"),e(s.includes("\\*"),"* 应被转义")}),t("转义结果可安全构造正则",function(){if(!n){e(!0,"(跳过)");return}var r="price: $10.00 (sale!)",s=new RegExp(RegExp.escape(r));e(s.test("price: $10.00 (sale!)"),"转义后的正则应能精确匹配原字符串"),e(!s.test("price: X10X00 Xsale!"),"不应匹配用特殊字符替换后的字符串")}),t("防止正则注入攻击",function(){if(!n){e(!0,"(跳过)");return}var r="(.*)",s=new RegExp(r),o=new RegExp(RegExp.escape(r));e(s.test("anything"),"未转义的正则可匹配任意字符串(注入漏洞)"),e(!o.test("anything"),'转义后只能匹配字面量 "(.*)"'),e(o.test("(.*)"),'转义后精确匹配字面字符串 "(.*)"')}),t("中文等 Unicode 字符不应被转义",function(){if(!n){e(!0,"(跳过)");return}var r="你好,世界";e(RegExp.escape(r)===r,"Unicode 字符不需要转义")}),t("空字符串返回空字符串",function(){if(!n){e(!0,"(跳过)");return}e(RegExp.escape("")==="","空字符串转义后应仍为空字符串")}),t("与 /g 标志组合 —— 高亮搜索词",function(){if(!n){e(!0,"(跳过)");return}var r="商品价格 $10.00,原价 $20.00",s="$10.00",o=new RegExp(RegExp.escape(s),"g"),u=(r.match(o)||[]).length;e(u===1,"含特殊字符的关键词应精确匹配 1 次")}),i()}function testExplicitResourceManagement(){return _testExplicitResourceManagement.apply(this,arguments)}function _testExplicitResourceManagement(){return _testExplicitResourceManagement=_asyncToGenerator(_regenerator().m(function a(){var t,e,i,n,r;return _regenerator().w(function(s){for(;;)switch(s.n){case 0:return t=createSuite("Explicit Resource Management (ES2026)"),e=t.test,i=t.assert,n=t.getResults,r=function(){try{try{var o=_usingCtx(),u=o.u("cx");return new Function("Symbol",`
|
|
6
6
|
const r = { [Symbol.dispose]() {} }
|
|
7
7
|
{ using x = r }
|
|
8
|
-
`)(Symbol),!0}catch{return!1}}(),e("环境支持检测",function(){
|
|
8
|
+
`)(Symbol),!0}catch(c){o.e=c}finally{o.d()}}catch{return!1}}(),e("环境支持检测",function(){i(r,"环境不支持 using / await using 语法")}),e("Symbol.dispose 已定义",function(){i(_typeof(Symbol.dispose)==="symbol","Symbol.dispose 应是 symbol 类型")}),e("Symbol.asyncDispose 已定义",function(){i(_typeof(Symbol.asyncDispose)==="symbol","Symbol.asyncDispose 应是 symbol 类型")}),e("using —— 块退出时自动调用 Symbol.dispose",function(){if(!r){i(!0,"(跳过:环境不支持 using 语法)");return}var o=[];new Function("log","Symbol",`
|
|
9
9
|
{
|
|
10
10
|
using r = {
|
|
11
11
|
[Symbol.dispose]() { log.push('disposed') }
|
|
@@ -13,18 +13,18 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
13
13
|
log.push('in-block')
|
|
14
14
|
}
|
|
15
15
|
log.push('after-block')
|
|
16
|
-
`)(o,Symbol),
|
|
16
|
+
`)(o,Symbol),i(o[0]==="in-block","块内代码应正常执行"),i(o[1]==="disposed","块退出时应自动调用 dispose"),i(o[2]==="after-block","dispose 之后块后代码才继续执行")}),e("using —— 异常时也会调用 dispose(保证清理)",function(){if(!r){i(!0,"(跳过)");return}var o=[];try{new Function("log","Symbol",`
|
|
17
17
|
{
|
|
18
18
|
using r = { [Symbol.dispose]() { log.push('cleanup') } }
|
|
19
19
|
throw new Error('意外错误')
|
|
20
20
|
}
|
|
21
|
-
`)(o,Symbol)}catch{}
|
|
21
|
+
`)(o,Symbol)}catch{}i(o[0]==="cleanup","即使抛出异常也应执行 dispose 清理")}),e("多个 using 资源按 LIFO 顺序释放",function(){if(!r){i(!0,"(跳过)");return}var o=[];new Function("order","Symbol",`
|
|
22
22
|
{
|
|
23
23
|
using a = { [Symbol.dispose]() { order.push('A') } }
|
|
24
24
|
using b = { [Symbol.dispose]() { order.push('B') } }
|
|
25
25
|
using c = { [Symbol.dispose]() { order.push('C') } }
|
|
26
26
|
}
|
|
27
|
-
`)(o,Symbol),
|
|
27
|
+
`)(o,Symbol),i(o.join(",")==="C,B,A","多资源应按 LIFO(后进先出)顺序释放")}),s.n=1,e("await using —— 异步 dispose",_asyncToGenerator(_regenerator().m(function o(){var u,c;return _regenerator().w(function(f){for(;;)switch(f.n){case 0:if(r){f.n=1;break}return i(!0,"(跳过)"),f.a(2);case 1:return u=[],c=new Function("log","Symbol",`
|
|
28
28
|
return (async () => {
|
|
29
29
|
{
|
|
30
30
|
await using r = {
|
|
@@ -37,6 +37,6 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
37
37
|
}
|
|
38
38
|
log.push('after-block')
|
|
39
39
|
})()
|
|
40
|
-
`),f.n=2,c(
|
|
40
|
+
`),f.n=2,c(u,Symbol);case 2:i(u[0]==="in-block","异步块内应正常执行"),i(u[1]==="async-disposed","await using 应等待异步 dispose 完成"),i(u[2]==="after-block","dispose 之后才继续执行块后代码");case 3:return f.a(2)}},o)})));case 1:return e("DisposableStack —— 手动管理资源栈",function(){if(typeof DisposableStack>"u"){i(!0,"(跳过:环境不支持 DisposableStack)");return}var o=[],u=new DisposableStack;u.defer(function(){return o.push("deferred-1")}),u.defer(function(){return o.push("deferred-2")}),u.dispose(),i(o.join(",")==="deferred-2,deferred-1","DisposableStack 应按 LIFO 执行")}),s.a(2,n())}},a)})),_testExplicitResourceManagement.apply(this,arguments)}function testAtomicsPause(){var a=createSuite("Atomics.pause() (ES2026)"),t=a.test,e=a.assert,i=a.getResults,n=typeof Atomics.pause=="function";return t("环境支持检测",function(){e(n,"环境不支持 Atomics.pause")}),t("Atomics.pause 函数存在",function(){if(!n){e(!0,"(跳过:环境不支持 Atomics.pause)");return}e(typeof Atomics.pause=="function","Atomics.pause 应为函数")}),t("无参数调用不抛出错误",function(){if(!n){e(!0,"(跳过)");return}var r=!1;try{Atomics.pause()}catch{r=!0}e(!r,"Atomics.pause() 无参数调用不应抛出")}),t("传入整数参数不抛出错误",function(){if(!n){e(!0,"(跳过)");return}var r=!1;try{Atomics.pause(0),Atomics.pause(1),Atomics.pause(100)}catch{r=!0}e(!r,"Atomics.pause(N) 应接受非负整数参数")}),t("返回值为 undefined",function(){if(!n){e(!0,"(跳过)");return}e(Atomics.pause()===void 0,"Atomics.pause() 应返回 undefined")}),t("自旋等待模式下连续调用不崩溃",function(){if(!n){e(!0,"(跳过)");return}for(var r=0;r<10;r++)Atomics.pause(r);e(r===10,"10 次自旋循环应正常完成")}),t("与 SharedArrayBuffer + Atomics.load 配合(模拟场景)",function(){if(!n){e(!0,"(跳过)");return}if(typeof SharedArrayBuffer>"u"){e(!0,"(跳过:环境不支持 SharedArrayBuffer)");return}var r=new SharedArrayBuffer(4),s=new Int32Array(r);s[0]=1;for(var o=0,u=5;Atomics.load(s,0)!==0&&o<u;)Atomics.pause(o),o++,o===3&&Atomics.store(s,0,0);e(Atomics.load(s,0)===0,"自旋等待后标志位应变为 0(锁释放)"),e(o===3,"应在第 3 次迭代时检测到锁释放")}),i()}function testImportAttributes(){return _testImportAttributes.apply(this,arguments)}function _testImportAttributes(){return _testImportAttributes=_asyncToGenerator(_regenerator().m(function a(){var t,e,i,n,r;return _regenerator().w(function(s){for(;;)switch(s.n){case 0:return t=createSuite("Import Attributes (ES2026)"),e=t.test,i=t.assert,n=t.getResults,r=function(){try{return new Function("import('data:text/javascript,export default 1', { with: { type: 'javascript' } })"),!0}catch{return!1}}(),e("环境支持检测",function(){i(r,"环境不支持 import with 语法")}),s.n=1,e("动态 import() 支持 with 选项对象",_asyncToGenerator(_regenerator().m(function o(){var u,c,f;return _regenerator().w(function(l){for(;;)switch(l.p=l.n){case 0:if(r){l.n=1;break}return i(!0,"(跳过:环境不支持 import with 语法)"),l.a(2);case 1:return u=null,l.p=2,c=new Function('return import("data:text/javascript,export default \\"hello\\"", { with: { type: "javascript" } })'),l.n=3,c();case 3:f=l.v,u=f.default,l.n=5;break;case 4:l.p=4,l.v,u="syntax-ok";case 5:i(u==="hello"||u==="syntax-ok","import with 语法应被环境支持");case 6:return l.a(2)}},o,null,[[2,4]])})));case 1:return e("import with 选项中 type 属性为字符串",function(){var o={with:{type:"json"}};i(typeof o.with.type=="string","type 属性应为字符串"),i(o.with.type==="json","json type 应正确设置")}),e("import() 的第二个参数结构",function(){var o=[{with:{type:"json"}},{with:{type:"css"}},{with:{type:"javascript"}}];o.forEach(function(u){i(u.with!==void 0,"options.with 应存在"),i(typeof u.with.type=="string","type 应为字符串")}),i(!0,"import() 选项结构验证通过")}),e("JSON 模块导入属性防止 MIME 混淆(原理说明)",function(){var o=!0;i(o,'JSON 模块导入应声明 type: "json" 防止 MIME 混淆攻击')}),e("import with 仅传递元信息,不影响模块标识符",function(){var o="./data.json",u={with:{type:"json"}},c={with:{type:"json"}};i(o==="./data.json","模块说明符不应被 with 属性修改"),i(u.with.type===c.with.type,"相同 type 的 options 应等价")}),s.a(2,n())}},a)})),_testImportAttributes.apply(this,arguments)}var suites2015=[{name:"let & const",fn:testLetConst},{name:"箭头函数",fn:testArrowFunctions},{name:"模板字符串",fn:testTemplateLiterals},{name:"解构赋值",fn:testDestructuring},{name:"默认参数 / Rest / Spread",fn:testDefaultRestSpread},{name:"类(Class)",fn:testClasses},{name:"Promise & async/await",fn:testPromises},{name:"Symbol",fn:testSymbols},{name:"迭代器与生成器",fn:testIteratorsGenerators},{name:"Map & Set & WeakMap & WeakSet",fn:testMapSet},{name:"Proxy & Reflect",fn:testProxyReflect},{name:"增强对象字面量",fn:testEnhancedObjects},{name:"新增内置方法",fn:testNewMethods},{name:"模块(Modules)",fn:testModules},{name:"进制字面量与 Unicode",fn:testBinaryOctalUnicode},{name:"for...of",fn:testForOf},{name:"Map getOrInsert",fn:testMapGetOrInsert}],suites2022=[{name:"Class Fields(私有字段 / 静态字段)",fn:testClassFields},{name:"Class Static Blocks",fn:testClassStaticBlocks},{name:"Array / String .at()",fn:testAtMethod},{name:"Object.hasOwn()",fn:testObjectHasOwn},{name:"Error Cause",fn:testErrorCause},{name:"RegExp /d flag(匹配索引)",fn:testRegExpDFlag},{name:"Top-level await",fn:testTopLevelAwait}],suites2025=[{name:"Iterator Helpers",fn:testIteratorHelpers},{name:"New Set Methods",fn:testSetMethods},{name:"Promise.try",fn:testPromiseTry},{name:"RegExp Duplicate Named Capture Groups",fn:testRegExpDuplicateGroups},{name:"Uint8Array Base64 / Hex",fn:testUint8ArrayBase64Hex},{name:"JSON.parse Source Text Access",fn:testJsonParseSource},{name:"Error.isError",fn:testErrorIsError},{name:"Float16Array",fn:testFloat16Array}],suites2026=[{name:"Math.sumPrecise()",fn:testMathSumPrecise},{name:"RegExp.escape()",fn:testRegExpEscape},{name:"Explicit Resource Management",fn:testExplicitResourceManagement},{name:"Atomics.pause()",fn:testAtomicsPause},{name:"Import Attributes",fn:testImportAttributes}];function runSuites(a){return _runSuites.apply(this,arguments)}function _runSuites(){return _runSuites=_asyncToGenerator(_regenerator().m(function a(t){var e,i,n,r,s,o;return _regenerator().w(function(u){for(;;)switch(u.p=u.n){case 0:e=[],i=_createForOfIteratorHelper(t),u.p=1,i.s();case 2:if((n=i.n()).done){u.n=5;break}return r=n.value,u.n=3,r.fn();case 3:s=u.v,e.push.apply(e,_toConsumableArray(s));case 4:u.n=2;break;case 5:u.n=7;break;case 6:u.p=6,o=u.v,i.e(o);case 7:return u.p=7,i.f(),u.f(7);case 8:return u.a(2,e)}},a,null,[[1,6,7,8]])})),_runSuites.apply(this,arguments)}function runAll2015(){return _runAll.apply(this,arguments)}function _runAll(){return _runAll=_asyncToGenerator(_regenerator().m(function a(){return _regenerator().w(function(t){for(;;)switch(t.n){case 0:return t.a(2,runSuites(suites2015))}},a)})),_runAll.apply(this,arguments)}function runAll2022(){return _runAll2.apply(this,arguments)}function _runAll2(){return _runAll2=_asyncToGenerator(_regenerator().m(function a(){return _regenerator().w(function(t){for(;;)switch(t.n){case 0:return t.a(2,runSuites(suites2022))}},a)})),_runAll2.apply(this,arguments)}function runAll2025(){return _runAll3.apply(this,arguments)}function _runAll3(){return _runAll3=_asyncToGenerator(_regenerator().m(function a(){return _regenerator().w(function(t){for(;;)switch(t.n){case 0:return t.a(2,runSuites(suites2025))}},a)})),_runAll3.apply(this,arguments)}function runAll2026(){return _runAll4.apply(this,arguments)}function _runAll4(){return _runAll4=_asyncToGenerator(_regenerator().m(function a(){return _regenerator().w(function(t){for(;;)switch(t.n){case 0:return t.a(2,runSuites(suites2026))}},a)})),_runAll4.apply(this,arguments)}function runAll(){return _runAll5.apply(this,arguments)}function _runAll5(){return _runAll5=_asyncToGenerator(_regenerator().m(function a(){return _regenerator().w(function(t){for(;;)switch(t.n){case 0:return t.a(2,runSuites([].concat(suites2015,suites2022,suites2025,suites2026)))}},a)})),_runAll5.apply(this,arguments)}function runAndPrint(){return _runAndPrint.apply(this,arguments)}function _runAndPrint(){return _runAndPrint=_asyncToGenerator(_regenerator().m(function a(){var t,e,i,n,r,s;return _regenerator().w(function(o){for(;;)switch(o.n){case 0:t=0,e=[["ES2015",runAll2015],["ES2022",runAll2022],["ES2025",runAll2025],["ES2026",runAll2026]];case 1:if(!(t<e.length)){o.n=4;break}return i=_slicedToArray(e[t],2),n=i[0],r=i[1],console.log(`
|
|
41
41
|
=== `.concat(n,` 特性测试 ===
|
|
42
42
|
`)),s=printResults,o.n=2,r();case 2:s(o.v);case 3:t++,o.n=1;break;case 4:return o.a(2)}},a)})),_runAndPrint.apply(this,arguments)}return exports.runAll=runAll,exports.runAll2015=runAll2015,exports.runAll2022=runAll2022,exports.runAll2025=runAll2025,exports.runAll2026=runAll2026,exports.runAndPrint=runAndPrint,exports.testArrowFunctions=testArrowFunctions,exports.testAtMethod=testAtMethod,exports.testAtomicsPause=testAtomicsPause,exports.testBinaryOctalUnicode=testBinaryOctalUnicode,exports.testClassFields=testClassFields,exports.testClassStaticBlocks=testClassStaticBlocks,exports.testClasses=testClasses,exports.testDefaultRestSpread=testDefaultRestSpread,exports.testDestructuring=testDestructuring,exports.testEnhancedObjects=testEnhancedObjects,exports.testErrorCause=testErrorCause,exports.testErrorIsError=testErrorIsError,exports.testExplicitResourceManagement=testExplicitResourceManagement,exports.testFloat16Array=testFloat16Array,exports.testForOf=testForOf,exports.testImportAttributes=testImportAttributes,exports.testIteratorHelpers=testIteratorHelpers,exports.testIteratorsGenerators=testIteratorsGenerators,exports.testJsonParseSource=testJsonParseSource,exports.testLetConst=testLetConst,exports.testMapGetOrInsert=testMapGetOrInsert,exports.testMapSet=testMapSet,exports.testMathSumPrecise=testMathSumPrecise,exports.testModules=testModules,exports.testNewMethods=testNewMethods,exports.testObjectHasOwn=testObjectHasOwn,exports.testPromiseTry=testPromiseTry,exports.testPromises=testPromises,exports.testProxyReflect=testProxyReflect,exports.testRegExpDFlag=testRegExpDFlag,exports.testRegExpDuplicateGroups=testRegExpDuplicateGroups,exports.testRegExpEscape=testRegExpEscape,exports.testSetMethods=testSetMethods,exports.testSymbols=testSymbols,exports.testTemplateLiterals=testTemplateLiterals,exports.testTopLevelAwait=testTopLevelAwait,exports.testUint8ArrayBase64Hex=testUint8ArrayBase64Hex,Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"}),exports}({});
|