Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit e0cfd5f

Browse files
committed
Fixed
1 parent e45a661 commit e0cfd5f

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

+23-20
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,29 @@ if (!global.URL.$$objects) {
1111
return `blob:http://localhost/${id}`;
1212
};
1313

14-
1514
try {
16-
var oldFetch = global.fetch || fetch__default;
17-
global.fetch = function (e, t) {
18-
return new Promise(function (t, o) {
19-
var n = new FileReader;
20-
n.onload = function () {
21-
var e = global.Response || fetch.Response;
22-
t(new e(n.result, {
23-
status: 200,
24-
statusText: "OK"
25-
}))
26-
}, n.onerror = function () {
27-
o(n.error)
28-
};
29-
var s = e.match(/[^/]+$/)[0];
30-
n.readAsText(global.URL.$$objects[s])
31-
})
32-
}
33-
} catch (err) { }
15+
let oldFetch = global.fetch || fetch;
16+
global.fetch = function (url, opts) {
17+
if (url.match(/^blob:/)) {
18+
return new Promise((resolve, reject) => {
19+
let fr = new FileReader();
20+
fr.onload = () => {
21+
let Res = global.Response || Response;
22+
resolve(new Res(fr.result, { status: 200, statusText: 'OK' }));
23+
};
24+
fr.onerror = () => {
25+
reject(fr.error);
26+
};
27+
let id = url.match(/[^/]+$/)[0];
28+
fr.readAsText(global.URL.$$objects[id]);
29+
});
30+
}
31+
return oldFetch.call(this, url, opts);
32+
};
33+
} catch (err) {
34+
35+
}
36+
3437

3538
}
3639

@@ -81,7 +84,7 @@ global.Worker = function Worker(url) {
8184
.then(code => {
8285
let vars = 'var self=this,global=self';
8386
for (let k in scope) vars += `,${k}=self.${k}`;
84-
getScopeVar = eval('(function() {' + vars + ';\n' + code + '\nreturn function(__){return eval(__)}})').call(scope);
87+
getScopeVar = eval('(function() {' + vars + '\n' + code + '\nreturn function(__){return eval(__)}})').call(scope);
8588
let q = messageQueue;
8689
messageQueue = null;
8790
q.forEach(this.postMessage);

0 commit comments

Comments
 (0)