From 51becf6943e2b4833ac16c077280454a1a98130c Mon Sep 17 00:00:00 2001 From: yutent Date: Wed, 19 Jul 2023 10:48:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=83=A8=E5=88=86=E8=AF=AD?= =?UTF-8?q?=E6=B3=95=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/checks.js | 39 ++++++++++++++++++++++++++++++++++++ src/store.js | 51 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 77 insertions(+), 13 deletions(-) diff --git a/src/lib/checks.js b/src/lib/checks.js index 5cc2c0a..fc4b8ca 100644 --- a/src/lib/checks.js +++ b/src/lib/checks.js @@ -31,3 +31,42 @@ export function checkMedia(type, isAudio = 1) { } return 0 } + +export function checkAsyncAwait() { + try { + eval('async function foo(){return await 123}') + return 1.25 + } catch (e) { + return 0 + } +} + +export function checkPrivateFeatures() { + try { + eval('class Foo { #bar = 3}') + return 1.25 + } catch (e) { + return 0 + } +} + +export function checkObjectSpread() { + try { + eval(`let a = [11, 22] + let b = [...a] + ;[a[1], a[0]] = [a[0], a[1]]`) + return 1 + } catch (e) { + return 0 + } +} + +export function checkOptionalChaining() { + try { + // ?。 和 ?? 同时期出现的, 检测一个即可 + window.a?.b?.c() + return 1 + } catch (e) { + return 0 + } +} diff --git a/src/store.js b/src/store.js index dd976a2..3ebeaf8 100644 --- a/src/store.js +++ b/src/store.js @@ -1,7 +1,14 @@ import { reactive } from 'vue' import * as env from '@/lib/env.js' -import { checkCanvas, checkMedia } from '@/lib/checks.js' +import { + checkCanvas, + checkMedia, + checkAsyncAwait, + checkPrivateFeatures, + checkObjectSpread, + checkOptionalChaining +} from '@/lib/checks.js' const store = reactive({ scores: 80, @@ -160,30 +167,48 @@ const store = reactive({ ] }, { - name: 'ES6模块', + name: '一些语法支持', total: 0, - factor: 40, - scores: [1, env.SUPPORT_ASSERTIONS ? 2.5 : 0], - items: ['import/export', 'Import assertions'] - }, - { - name: '性能', - total: 0, - factor: 70, - scores: [!!navigator.serviceWorker ^ 0, window.WebAssembly ? 1.5 : 0], - items: ['Web Workers', 'WebAssembly'] + factor: 60, + scores: [ + !!window.BigInt ^ 0, + checkObjectSpread(), + checkOptionalChaining(), + 1 /* 能打开这个页面, 就是支持esm的了 */, + env.SUPPORT_ASSERTIONS ? 2.5 : 0, + checkAsyncAwait(), + checkPrivateFeatures() + ], + items: [ + 'BigInt', + 'Object Spread', + '?. and ??', + 'import/export', + 'Import assertions', + 'async / await', + 'Private class features' + ] }, { name: '其他', total: 0, factor: 80, scores: [ + !!navigator.serviceWorker ^ 0, + window.WebAssembly ? 1.5 : 0, !!navigator.bluetooth ^ 0, navigator.clipboard ? 0.8 : 0, navigator.usb ? 2 : 0, !!navigator.windowControlsOverlay ^ 0 ], - items: ['Bluetooth', 'clipboard', 'USB', 'Window Controls Overlay'] + items: [ + 'Web Workers', + 'WebAssembly', + 'Bluetooth', + 'clipboard', + 'USB', + 'Window Controls Overlay' + ] } ] })