|
1 | | -/* eslint-disable no-extend-native */ |
2 | | -// @ts-ignore |
3 | 1 | import WASM from 'wasm' |
4 | 2 |
|
5 | | -// polyfills for old or weird engines |
6 | | - |
7 | | -if (!String.prototype.startsWith) { |
8 | | - String.prototype.startsWith = function (s, p = 0) { |
9 | | - return this.substring(p, s.length) === s |
10 | | - } |
11 | | -} |
12 | | - |
13 | | -if (!String.prototype.includes) { |
14 | | - String.prototype.includes = function (s, p) { |
15 | | - return this.indexOf(s, p) !== -1 |
16 | | - } |
17 | | -} |
18 | | - |
19 | | -if (!Uint8Array.prototype.slice) { |
20 | | - Uint8Array.prototype.slice = function (b, e) { |
21 | | - return new Uint8Array(this.subarray(b, e)) |
22 | | - } |
23 | | -} |
24 | | - |
25 | | -function toAbsoluteIndex (index, length) { |
26 | | - const integer = index >> 0 |
27 | | - return integer < 0 ? Math.max(integer + length, 0) : Math.min(integer, length) |
28 | | -} |
29 | | - |
30 | | -if (!Uint8Array.prototype.fill) { |
31 | | - Int8Array.prototype.fill = Int16Array.prototype.fill = Int32Array.prototype.fill = Uint8Array.prototype.fill = Uint16Array.prototype.fill = Uint32Array.prototype.fill = Float32Array.prototype.fill = Float64Array.prototype.fill = Array.prototype.fill = function (value) { |
32 | | - if (this == null) throw new TypeError('this is null or not defined') |
33 | | - |
34 | | - const O = Object(this) |
35 | | - |
36 | | - const length = O.length >>> 0 |
37 | | - |
38 | | - const argumentsLength = arguments.length |
39 | | - let index = toAbsoluteIndex(argumentsLength > 1 ? arguments[1] : undefined, length) |
40 | | - const end = argumentsLength > 2 ? arguments[2] : undefined |
41 | | - const endPos = end === undefined ? length : toAbsoluteIndex(end, length) |
42 | | - while (endPos > index) O[index++] = value |
43 | | - return O |
44 | | - } |
45 | | -} |
46 | | - |
47 | | -if (!Uint8Array.prototype.copyWithin) { |
48 | | - Int8Array.prototype.copyWithin = Int16Array.prototype.copyWithin = Int32Array.prototype.copyWithin = Uint8Array.prototype.copyWithin = Uint16Array.prototype.copyWithin = Uint32Array.prototype.copyWithin = Float32Array.prototype.copyWithin = Float64Array.prototype.copyWithin = Array.prototype.copyWithin = function (target, start) { |
49 | | - const O = Object(this) |
50 | | - const len = O.length >>> 0 |
51 | | - |
52 | | - let to = toAbsoluteIndex(target, len) |
53 | | - let from = toAbsoluteIndex(start, len) |
54 | | - const end = arguments.length > 2 ? arguments[2] : undefined |
55 | | - let count = Math.min((end === undefined ? len : toAbsoluteIndex(end, len)) - from, len - to) |
56 | | - let inc = 1 |
57 | | - if (from < to && to < from + count) { |
58 | | - inc = -1 |
59 | | - from += count - 1 |
60 | | - to += count - 1 |
61 | | - } |
62 | | - while (count-- > 0) { |
63 | | - if (from in O) O[to] = O[from] |
64 | | - else delete O[to] |
65 | | - to += inc |
66 | | - from += inc |
67 | | - } return O |
68 | | - } |
69 | | -} |
70 | | - |
71 | | -if (!Date.now) Date.now = () => new Date().getTime() |
72 | | -// @ts-ignore |
73 | | -if (!('performance' in self)) self.performance = { now: () => Date.now() } |
74 | | - |
75 | | -// implement console methods if they're missing |
76 | | -if (typeof console === 'undefined') { |
77 | | - const msg = (command, a) => { |
78 | | - postMessage({ |
79 | | - target: 'console', |
80 | | - command, |
81 | | - content: JSON.stringify(Array.prototype.slice.call(a)) |
82 | | - }) |
83 | | - } |
84 | | - // @ts-ignore |
85 | | - self.console = { |
86 | | - log: function () { |
87 | | - msg('log', arguments) |
88 | | - }, |
89 | | - debug: function () { |
90 | | - msg('debug', arguments) |
91 | | - }, |
92 | | - info: function () { |
93 | | - msg('info', arguments) |
94 | | - }, |
95 | | - warn: function () { |
96 | | - msg('warn', arguments) |
97 | | - }, |
98 | | - error: function () { |
99 | | - msg('error', arguments) |
100 | | - } |
101 | | - } |
102 | | - console.log('Detected lack of console, overridden console') |
103 | | -} |
104 | | - |
105 | | -let promiseSupported = typeof Promise !== 'undefined' |
106 | | - |
107 | | -// some engines report that Promise resolve isn't a function... what?... |
108 | | -if (promiseSupported) { |
109 | | - try { |
110 | | - let res |
111 | | - // eslint-disable-next-line no-new |
112 | | - new Promise(resolve => { res = resolve }) |
113 | | - res() |
114 | | - } catch (error) { |
115 | | - promiseSupported = false |
116 | | - } |
117 | | -} |
118 | | - |
119 | | -// very bad promise polyfill, it's absolutely minimal just to make emscripten work |
120 | | -// in engines that don't have promises, Promise should never be used otherwise |
121 | | -if (!promiseSupported) { |
122 | | - // @ts-ignore |
123 | | - self.Promise = function (cb) { |
124 | | - let then = () => {} |
125 | | - cb(a => setTimeout(() => then(a), 0)) |
126 | | - return { then: fn => then = fn } |
127 | | - } |
128 | | -} |
129 | | - |
130 | 3 | const read_ = (url, ab) => { |
131 | 4 | const xhr = new XMLHttpRequest() |
132 | 5 | xhr.open('GET', url, false) |
@@ -170,7 +43,7 @@ self.addFont = ({ font }) => asyncWrite(font) |
170 | 43 | const findAvailableFonts = font => { |
171 | 44 | font = font.trim().toLowerCase() |
172 | 45 |
|
173 | | - if (font.startsWith('@')) font = font.substring(1) |
| 46 | + if (font[0] === '@') font = font.substring(1) |
174 | 47 |
|
175 | 48 | if (fontMap_[font]) return |
176 | 49 |
|
|
0 commit comments