Skip to content

Commit e003c32

Browse files
Fix worker tests using the wrong paths in importScripts (#8050)
Worker tests were getting the path for `importScripts` by referencing `location.origin`, but this is `blob://` when accessed from the worker context. Template `location.origin` from the main context into the worker source code instead of accessing the worker's version of `location.origin`.
1 parent 18c4224 commit e003c32

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

tfjs-core/src/worker_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ const str2workerURL = (str: string): string => {
2626

2727
// The source code of a web worker.
2828
const workerTest = `
29-
importScripts(location.origin + '/base/tfjs/tfjs-core/tf-core.min.js');
30-
importScripts(location.origin
29+
importScripts('${location.origin}/base/tfjs/tfjs-core/tf-core.min.js');
30+
importScripts('${location.origin}'
3131
+ '/base/tfjs/tfjs-backend-cpu/tf-backend-cpu.min.js');
3232
3333
let a = tf.tensor1d([1, 2, 3]);

tfjs-tflite/src/worker_test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ const str2workerURL = (str: string): string => {
2525

2626
// The source code of a web worker.
2727
const workerTest = `
28-
importScripts(location.origin + '/base/tfjs/tfjs-core/tf-core.min.js');
29-
importScripts(location.origin
28+
importScripts('${location.origin}/base/tfjs/tfjs-core/tf-core.min.js');
29+
importScripts('${location.origin}'
3030
+ '/base/tfjs/tfjs-backend-cpu/tf-backend-cpu.min.js');
3131
// Import order matters. TFLite must be imported after tfjs core.
32-
importScripts(location.origin + '/base/tfjs/tfjs-tflite/tf-tflite.min.js');
32+
importScripts('${location.origin}/base/tfjs/tfjs-tflite/tf-tflite.min.js');
3333
3434
// Setting wasm path is required. It can be set to CDN if needed,
3535
// but that's not a good idea for a test.
36-
tflite.setWasmPath('/base/tfjs/tfjs-tflite/wasm/');
36+
tflite.setWasmPath('${location.origin}/base/tfjs/tfjs-tflite/wasm/');
3737
async function main() {
3838
// This is a test model that adds two tensors of shape [1, 4].
39-
const model = await tflite.loadTFLiteModel(location.origin + '/base/tfjs/tfjs-tflite/test_files/add4.tflite');
39+
const model = await tflite.loadTFLiteModel('${location.origin}/base/tfjs/tfjs-tflite/test_files/add4.tflite');
4040
4141
const a = tf.tensor2d([[1, 2, 3, 4]]);
4242
const b = tf.tensor2d([[5, 6, 7, 8]]);

0 commit comments

Comments
 (0)