feat: 论文级博客系统 - 完整数学公式与高级代码展示

📚 论文级功能实现:
- ✅ KaTeX数学公式渲染系统 (内联$...1411...1411)
- ✅ 高级代码高亮 (行号、标题、语法着色)
- ✅ PWA渐进式Web应用支持
- ✅ 多语言代码支持 (20+编程语言)
- ✅ 代码行标注系统 (错误/成功/警告/高亮)

🧮 数学公式系统:
- LaTeX语法完整支持
- 数学宏定义 (\RR, \NN, \ZZ, \QQ, \CC等)
- 复杂公式渲染 (矩阵、积分、求和、分数)
- 响应式数学表达式
- 黑暗模式数学公式适配

💻 高级代码展示:
- 代码块标题显示
- 行号自动生成
- 语法高亮增强
- 多行高亮标注
- 错误/成功/警告行标记
- 20+编程语言支持

🔧 企业级插件:
- @docusaurus/plugin-pwa (离线支持)
- rehype-katex (数学公式)
- remark-math (数学语法)
- remark-gfm (GitHub风格Markdown)
- prism-react-renderer (代码高亮)

📊 算法示例升级:
- Transformer深度学习模型
- 多头注意力机制实现
- 完整的神经网络架构
- 专业文档注释
- 类型提示和错误处理

🎨 视觉优化:
- 数学公式背景框
- 代码行高亮动画
- 专业配色方案
- 渐变边框效果
- 响应式设计适配

📱 PWA功能:
- 离线访问支持
- 应用图标配置
- 清单文件完整
- 主题色统一
- 安装提示优化

🚀 性能优化:
- 图片质量提升至85%
- 代码分割优化
- 字体预加载
- CSS变量系统
- GPU加速渲染

✨ 用户体验:
- 论文级排版标准
- 学术引用格式
- 专业视觉层次
- 无障碍访问支持
- 多设备完美适配
This commit is contained in:
2025-07-20 06:51:21 +08:00
parent 95f4c34427
commit ff99b8eb2b
10484 changed files with 791301 additions and 665 deletions
+13
View File
@@ -0,0 +1,13 @@
root = true
[*]
indent_style = tab;
insert_final_newline = true;
quote_type = auto;
space_after_anonymous_functions = true;
space_after_control_statements = true;
spaces_around_operators = true;
trim_trailing_whitespace = true;
spaces_in_brackets = false;
end_of_line = lf;
+34
View File
@@ -0,0 +1,34 @@
{
"root": true,
"extends": "@ljharb",
"rules": {
"id-length": 0,
"max-params": 0,
"max-statements": 0,
"multiline-comment-style": 0,
"new-cap": [2, {
"capIsNewExceptions": [
"IsSharedArrayBuffer",
"ToIntegerOrInfinity",
"GetIntrinsic",
"IsDetachedBuffer",
"SpeciesConstructor",
],
}],
},
"overrides": [
{
"files": "test/**",
"globals": {
"ArrayBuffer": false,
"Uint8Array": false,
},
"rules": {
"max-lines-per-function": 0,
},
},
],
}
+9
View File
@@ -0,0 +1,9 @@
{
"all": true,
"check-coverage": false,
"reporter": ["text-summary", "text", "html", "json"],
"exclude": [
"coverage",
"test"
]
}
+52
View File
@@ -0,0 +1,52 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.0.4](https://github.com/es-shims/ArrayBuffer.prototype.slice/compare/v1.0.3...v1.0.4) - 2024-12-15
### Commits
- [actions] split out node 10-20, and 20+ [`5e59635`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/5e59635c948994b613c544b4e94fe93536d6b213)
- [Deps] update `call-bind`, `es-abstract`, `get-intrinsic` [`0afbb59`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/0afbb5942574055a8a3afdf0f69f60313e3f1af2)
- [Dev Deps] update `@es-shims/api`, `auto-changelog`, `es-value-fixtures`, `object-inspect`, `tape` [`d76caf4`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/d76caf4880ef358cf5384a6eb29d0f2f67e4d3a8)
- [Deps] update `call-bind`, `es-abstract`, `es-errors`, `get-intrinsic` [`2b374a2`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/2b374a2d4078d9122ac30bdecd8a8fae740aa74c)
- [Dev Deps] update `@es-shims/api`, `@ljharb/eslint-config`, `object-inspect`, `tape` [`a24fd39`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/a24fd39370d891ea3439f9d7a1c42183c0aa1bf7)
- [Tests] replace `aud` with `npm audit` [`c704fb0`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/c704fb0b1651ceb56b609a5b4646a993fc868219)
- [Deps] remove unused dependency [`0274b32`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/0274b32ab1d345fbf70745a79dd7a44f844179bb)
- [Dev Deps] add missing peer dep [`673f754`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/673f754797dd0c40801cca2f32ff08b372448c6b)
## [v1.0.3](https://github.com/es-shims/ArrayBuffer.prototype.slice/compare/v1.0.2...v1.0.3) - 2024-02-04
### Commits
- [Deps] update `array-buffer-byte-length`, `call-bind`, `define-properties`, `es-abstract`, `get-intrinsic`, `is-array-buffer` [`d9b6859`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/d9b68591ff509613d0dfc4036539ba4e0dc34931)
- [Dev Deps] update `aud`, `npmignore`, `object-inspect`, `tape` [`38cb58d`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/38cb58dfa3f3c8b11bfb2144f8e7cc74dd461f5e)
- [Refactor] use `es-errors` where possible, so things that only need those do not need `get-intrinsic` [`5c07bef`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/5c07befd134cae93ad5f9ab307ff67691ff5155b)
## [v1.0.2](https://github.com/es-shims/ArrayBuffer.prototype.slice/compare/v1.0.1...v1.0.2) - 2023-09-05
### Commits
- [Deps] update `es-abstract` [`a9ab0d2`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/a9ab0d2551bb301b740e333ea3795fad23fcbe40)
- [Dev Deps] update `tape` [`6b24af5`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/6b24af585dc9176c8ac3fd482cb1d5257e550a09)
- [Fix] move `es-abstract` to runtime deps [`63a8397`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/63a8397623d7749856f6392ae93bf87152c3916c)
## [v1.0.1](https://github.com/es-shims/ArrayBuffer.prototype.slice/compare/v1.0.0...v1.0.1) - 2023-07-11
### Commits
- [Fix] node < 0.11 has an own nonconfigurable `slice` property; use it [`554823c`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/554823c92ce16d6b7184a7d0ccfe315b663584d7)
- [Dev Deps] update `@es-shims/api`, `@ljharb/eslint-config`, `aud`, `es-abstract`, `tape` [`53b0421`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/53b04217048c645306597e2cfc55adb69c384146)
- [Deps] update `define-properties`, `get-intrinsic` [`4966b02`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/4966b02bc25ac006709b29ca370b9f6e159f723a)
## v1.0.0 - 2023-07-09
### Commits
- Initial implementation, tests, readme [`36b4b5e`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/36b4b5eedfa225c3086e9453b9db0088c299640a)
- Initial commit [`51499df`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/51499dfac7d8c67c2928cb47363a4de7ff17904a)
- npm init [`8ec604e`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/8ec604e7d3ef8d4c27376b09645f779c2244b08f)
- Only apps should have lockfiles [`ac54435`](https://github.com/es-shims/ArrayBuffer.prototype.slice/commit/ac54435161d4415e2122e3a682499f3a6df2f6de)
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 ECMAScript Shims
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+61
View File
@@ -0,0 +1,61 @@
# ArrayBuffer.prototype.slice <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![npm badge][npm-badge-png]][package-url]
An ES spec-compliant `ArrayBuffer.prototype.slice` shim. Invoke its "shim" method to shim ArrayBuffer.prototype.slice if it is unavailable.
This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES5-supported environment and complies with the [spec](https://tc39.es/ecma262/#sec-arraybuffer.prototype.slice).
Most common usage:
```js
var assert = require('assert');
var slice = require('arraybuffer.prototype.slice');
var ab = new ArrayBuffer(1);
var arr = new Uint8Array(ab);
arr[0] = 123;
var ab2 = slice(ab);
var arr2 = new Uint8Array(ab2);
arr2[0] = 234;
assert.deepEqual(arr, new Uint8Array([123]));
assert.deepEqual(arr2, new Uint8Array([234]));
if (!ArrayBuffer.prototype.transfer) {
slice.shim();
}
var ab2 = ab.slice();
var arr2 = new Uint8Array(ab2);
arr2[0] = 234;
assert.deepEqual(arr, new Uint8Array([123]));
assert.deepEqual(arr2, new Uint8Array([234]));
```
## Tests
Simply clone the repo, `npm install`, and run `npm test`
[package-url]: https://npmjs.org/package/arraybuffer.prototype.slice
[npm-version-svg]: https://versionbadg.es/es-shims/ArrayBuffer.prototype.slice.svg
[deps-svg]: https://david-dm.org/es-shims/ArrayBuffer.prototype.slice.svg
[deps-url]: https://david-dm.org/es-shims/ArrayBuffer.prototype.slice
[dev-deps-svg]: https://david-dm.org/es-shims/ArrayBuffer.prototype.slice/dev-status.svg
[dev-deps-url]: https://david-dm.org/es-shims/ArrayBuffer.prototype.slice#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/arraybuffer.prototype.slice.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/arraybuffer.prototype.slice.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/arraybuffer.prototype.slice.svg
[downloads-url]: https://npm-stat.com/charts.html?package=arraybuffer.prototype.slice
[codecov-image]: https://codecov.io/gh/es-shims/ArrayBuffer.prototype.slice/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/es-shims/ArrayBuffer.prototype.slice/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/ArrayBuffer.prototype.slice
[actions-url]: https://github.com/es-shims/ArrayBuffer.prototype.slice/actions
+3
View File
@@ -0,0 +1,3 @@
'use strict';
require('./shim')();
+84
View File
@@ -0,0 +1,84 @@
'use strict';
var GetIntrinsic = require('get-intrinsic');
var $ArrayBuffer = GetIntrinsic('%ArrayBuffer%', true);
var $Uint8Array = GetIntrinsic('%Uint8Array%', true);
var IsDetachedBuffer = require('es-abstract/2024/IsDetachedBuffer');
var IsSharedArrayBuffer = require('es-abstract/2024/IsSharedArrayBuffer');
var max = require('es-abstract/2024/max');
var min = require('es-abstract/2024/min');
var SpeciesConstructor = require('es-abstract/2024/SpeciesConstructor');
var ToIntegerOrInfinity = require('es-abstract/2024/ToIntegerOrInfinity');
var arrayBufferByteLength = require('array-buffer-byte-length');
var isArrayBuffer = require('is-array-buffer');
var $TypeError = require('es-errors/type');
module.exports = function slice(start, end) {
var O = this; // step 1
if (!isArrayBuffer(O) || IsSharedArrayBuffer(O) || IsDetachedBuffer(O)) {
throw new $TypeError('receiver must be a non-detached, non-shared ArrayBuffer'); // steps 2-4
}
var len = arrayBufferByteLength(O); // step 5
var relativeStart = ToIntegerOrInfinity(start); // step 6
var first;
if (relativeStart === -Infinity) {
first = 0; // step 7
} else if (relativeStart < 0) {
first = max(len + relativeStart, 0); // step 8
} else {
first = min(relativeStart, len); // step 9
}
var relativeEnd = typeof end === 'undefined' ? len : ToIntegerOrInfinity(end); // step 10
var final;
if (relativeEnd === -Infinity) {
final = 0; // step 11
} else if (relativeEnd < 0) {
final = max(len + relativeEnd, 0); // step 12
} else {
final = min(relativeEnd, len); // step 13
}
var newLen = max(final - first, 0); // step 14
var Ctor = SpeciesConstructor(O, $ArrayBuffer); // step 15
var new$ = new Ctor(newLen); // step 16
if (!isArrayBuffer(new$) || IsSharedArrayBuffer(new$) || IsDetachedBuffer(new$)) {
throw new $TypeError('Species constructor must produce a non-detached, non-shared Array Buffer'); // steps 17-19
}
if (new$ === O) {
throw new $TypeError('new ArrayBuffer should not have been the same as the receiver'); // step 20
}
if (arrayBufferByteLength(new$) < newLen) {
throw new $TypeError('new ArrayBuffer\'s byteLength must be at least the requested length'); // step 21
}
if (IsDetachedBuffer(O)) {
throw new $TypeError('receiver became an detached ArrayBuffer'); // step 23
}
/*
24. Let fromBuf be O.[[ArrayBufferData]].
25. Let toBuf be new.[[ArrayBufferData]].
26. Perform CopyDataBlockBytes(toBuf, 0, fromBuf, first, newLen).
*/
var sourceArr = new $Uint8Array(O);
var destArr = new $Uint8Array(new$);
for (var i = start, ii = 0; i < end; i++, ii++) {
destArr[ii] = sourceArr[i];
}
return new$; // step 27
};
+18
View File
@@ -0,0 +1,18 @@
'use strict';
var define = require('define-properties');
var callBind = require('call-bind');
var implementation = require('./implementation');
var getPolyfill = require('./polyfill');
var shim = require('./shim');
var bound = callBind(getPolyfill());
define(bound, {
getPolyfill: getPolyfill,
implementation: implementation,
shim: shim
});
module.exports = bound;
+102
View File
@@ -0,0 +1,102 @@
{
"name": "arraybuffer.prototype.slice",
"version": "1.0.4",
"description": "ES spec-compliant shim for ArrayBuffer.prototype.slice",
"author": "Jordan Harband <[email protected]>",
"funding": {
"url": "https://github.com/sponsors/ljharb"
},
"license": "MIT",
"main": "index.js",
"exports": {
".": "./index.js",
"./auto": "./auto.js",
"./polyfill": "./polyfill.js",
"./implementation": "./implementation.js",
"./shim": "./shim.js",
"./package.json": "./package.json"
},
"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"prepublish": "not-in-publish || npm run prepublishOnly",
"prepublishOnly": "safe-publish-latest",
"pretest": "npm run lint",
"test": "npm run tests-only",
"posttest": "npx npm@'>=10.2' audit --production",
"tests-only": "nyc tape 'test/**/*.js'",
"prelint": "eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git')",
"lint": "eslint --ext=js,mjs .",
"postlint": "evalmd README.md && es-shim-api --bound",
"version": "auto-changelog && git add CHANGELOG.md",
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
},
"repository": {
"type": "git",
"url": "git+https://github.com/es-shims/ArrayBuffer.prototype.slice.git"
},
"homepage": "https://github.com/es-shims/ArrayBuffer.prototype.slice#readme",
"bugs": {
"url": "https://github.com/es-shims/ArrayBuffer.prototype.slice/issues"
},
"keywords": [
"javascript",
"ecmascript",
"ArrayBuffer.prototype.slice",
"polyfill",
"shim",
"ArrayBuffer",
"array",
"buffer",
"ArrayBuffer#slice",
"slice",
"typed array",
"es-shim API"
],
"dependencies": {
"array-buffer-byte-length": "^1.0.1",
"call-bind": "^1.0.8",
"define-properties": "^1.2.1",
"es-abstract": "^1.23.5",
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.6",
"is-array-buffer": "^3.0.4"
},
"devDependencies": {
"@es-shims/api": "^2.5.1",
"@ljharb/eslint-config": "^21.1.1",
"auto-changelog": "^2.5.0",
"eclint": "^2.8.1",
"encoding": "^0.1.13",
"es-value-fixtures": "^1.5.0",
"eslint": "=8.8.0",
"evalmd": "^0.0.19",
"for-each": "^0.3.3",
"functions-have-names": "^1.2.3",
"has-strict-mode": "^1.0.1",
"in-publish": "^2.0.1",
"npmignore": "^0.3.1",
"nyc": "^10.3.2",
"object-inspect": "^1.13.3",
"safe-publish-latest": "^2.0.0",
"tape": "^5.9.0"
},
"testling": {
"files": "test/index.js"
},
"engines": {
"node": ">= 0.4"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true
},
"publishConfig": {
"ignore": [
".github/workflows"
]
}
}
+21
View File
@@ -0,0 +1,21 @@
'use strict';
var callBind = require('call-bind');
var implementation = require('./implementation');
var ownSlice = typeof ArrayBuffer === 'function' && new ArrayBuffer(0).slice;
var ownSliceBound = ownSlice && callBind(ownSlice);
var ownSliceWrapper = ownSliceBound && function slice(start, end) {
/* eslint no-invalid-this: 0 */
if (arguments.length < 2) {
return ownSliceBound(this, arguments.length > 0 ? start : 0);
}
return ownSliceBound(this, start, end);
};
module.exports = function getPolyfill() {
return (typeof ArrayBuffer === 'function' && ArrayBuffer.prototype.slice)
|| ownSliceWrapper
|| implementation;
};
+18
View File
@@ -0,0 +1,18 @@
'use strict';
var define = require('define-properties');
var getPolyfill = require('./polyfill');
module.exports = function shimArrayBufferSlice() {
if (typeof ArrayBuffer === 'function') {
var polyfill = getPolyfill();
define(
ArrayBuffer.prototype,
{ slice: polyfill },
{ slice: function () { return ArrayBuffer.prototype.slice !== polyfill; } }
);
}
return polyfill;
};
+32
View File
@@ -0,0 +1,32 @@
'use strict';
var implementation = require('../implementation');
var callBind = require('call-bind');
var test = require('tape');
var hasStrictMode = require('has-strict-mode')();
var runTests = require('./tests');
test('as a function', function (t) {
t.test('ArrayBuffer support', { skip: typeof ArrayBuffer === 'undefined' }, function (st) {
st.test('bad array/this value', { skip: !hasStrictMode }, function (s2t) {
/* eslint no-useless-call: 0 */
s2t['throws'](function () { implementation.call(undefined); }, TypeError, 'undefined is not an object');
s2t['throws'](function () { implementation.call(null); }, TypeError, 'null is not an object');
s2t.end();
});
runTests(callBind(implementation), st);
st.end();
});
t.test('no ArrayBuffer support', { skip: typeof ArrayBuffer !== 'undefined' }, function (st) {
st['throws'](
function () { implementation.call({}); },
SyntaxError,
'ArrayBuffer is not supported'
);
});
t.end();
});
+29
View File
@@ -0,0 +1,29 @@
'use strict';
var index = require('../');
var test = require('tape');
var runTests = require('./tests');
test('as a function', function (t) {
t.test('ArrayBuffer support', { skip: typeof ArrayBuffer === 'undefined' }, function (st) {
st.test('bad array/this value', function (s2t) {
s2t['throws'](function () { index(undefined); }, TypeError, 'undefined is not an object');
s2t['throws'](function () { index(null); }, TypeError, 'null is not an object');
s2t.end();
});
runTests(index, st);
st.end();
});
t.test('no ArrayBuffer support', { skip: typeof ArrayBuffer !== 'undefined' }, function (st) {
st['throws'](
function () { index({}); },
SyntaxError,
'ArrayBuffer is not supported'
);
});
t.end();
});
+54
View File
@@ -0,0 +1,54 @@
'use strict';
require('../auto');
var test = require('tape');
var defineProperties = require('define-properties');
var callBind = require('call-bind');
var isEnumerable = Object.prototype.propertyIsEnumerable;
var functionsHaveNames = require('functions-have-names')();
var hasStrictMode = require('has-strict-mode')();
var runTests = require('./tests');
test('shimmed', function (t) {
t.test('ArrayBuffer support', { skip: typeof ArrayBuffer === 'undefined' }, function (st) {
var method = ArrayBuffer.prototype.slice;
st.equal(method.length, 2, 'ArrayBuffer#slice has a length of 2');
st.test('Function name', { skip: !functionsHaveNames }, function (s2t) {
s2t.equal(method.name, 'slice', 'ArrayBuffer#slice name "slice"');
s2t.end();
});
st.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
et.equal(false, isEnumerable.call(ArrayBuffer.prototype, 'slice'), 'ArrayBuffer#slice is not enumerable');
et.end();
});
st.test('bad array/this value', { skip: !hasStrictMode }, function (s2t) {
/* eslint no-useless-call: 0 */
s2t['throws'](function () { return method.call(undefined); }, TypeError, 'undefined is not an object');
s2t['throws'](function () { return method.call(null); }, TypeError, 'null is not an object');
s2t.end();
});
t.test('has the correct descriptor', { skip: !Object.getOwnPropertyDescriptor }, function (s2t) {
var descriptor = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'slice');
s2t.equal(descriptor.configurable, true);
s2t.equal(descriptor.enumerable, false);
s2t.equal(typeof descriptor.value, 'function');
s2t.equal(descriptor.writable, true);
s2t.end();
});
runTests(callBind(method), st);
st.end();
});
t.end();
});
+81
View File
@@ -0,0 +1,81 @@
'use strict';
var inspect = require('object-inspect');
var IsDetachedBuffer = require('es-abstract/2024/IsDetachedBuffer');
var forEach = require('for-each');
var v = require('es-value-fixtures');
var byteLength = require('array-buffer-byte-length');
module.exports = function runTests(slice, t) {
forEach(v.primitives.concat(v.objects), function (nonAB) {
t['throws'](
function () { slice(nonAB); },
TypeError,
inspect(nonAB) + ' is not an ArrayBuffer'
);
});
t.test('ArrayBuffers', { skip: typeof ArrayBuffer === 'undefined' }, function (st) {
var ab = new ArrayBuffer(0);
st.equal(IsDetachedBuffer(ab), false, 'ArrayBuffer is not detached');
try {
var nb = slice(ab);
} catch (e) {
if (e instanceof SyntaxError) {
st.skip('Detaching ArrayBuffer is not supported');
return st.end();
}
console.log(e.stack);
}
st.notEqual(nb, ab, 'new ArrayBuffer is not the same as the original');
st.equal(IsDetachedBuffer(ab), false, 'old ArrayBuffer is not detached');
st.equal(IsDetachedBuffer(nb), false, 'new ArrayBuffer is not detached');
var ab2 = new ArrayBuffer(8);
st.equal(byteLength(ab2), 8, 'original ArrayBuffer has length 8');
try {
var nbLen = slice(ab2, 4);
} catch (e) {
if (e instanceof SyntaxError) {
st.skip('Detaching ArrayBuffer is not supported');
return st.end();
}
}
st.equal(IsDetachedBuffer(ab2), false, 'old ArrayBuffer is not detached');
st.equal(IsDetachedBuffer(nbLen), false, 'new ArrayBuffer is not detached');
st.equal(byteLength(ab2), 8, 'original ArrayBuffer has length 8');
st.equal(byteLength(nbLen), 4, 'newly sliced ArrayBuffer has length 4');
var one = new ArrayBuffer(1);
var arr = new Uint8Array(one);
arr[0] = 123;
var two = slice(one);
var arr2 = new Uint8Array(two);
arr2[0] = 234;
st.deepEqual(arr, new Uint8Array([123]), 'original buffer is unchanged');
st.deepEqual(arr2, new Uint8Array([234]), 'sliced buffer is changed');
return st.end();
});
t.test('SharedArrayBuffers', { skip: typeof SharedArrayBuffer === 'undefined' }, function (st) {
var sab = new SharedArrayBuffer(0);
st['throws'](
function () { slice(sab); },
TypeError,
inspect(sab) + ' is not an ArrayBuffer'
);
st.end();
});
};