Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@types/chai": "~3.4.0",
"@types/glob": "~5.0.0",
"@types/grunt": "~0.4.0",
"@types/node": "~6.0.0",
"dts-generator": "~2.0.0",
"grunt": "^1.0.1",
"grunt-contrib-uglify": "^2.0.0",
Expand Down
16 changes: 16 additions & 0 deletions src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ declare const Packages: {} | undefined;
has.add('host-browser', typeof document !== 'undefined' && typeof location !== 'undefined');
has.add('host-node', typeof process === 'object' && process.versions && process.versions.node);
has.add('host-nashorn', typeof load === 'function' && typeof Packages !== 'undefined');
has.add('host-web-worker', !has('host-browser') && typeof importScripts !== 'undefined');
has.add('debug', true);

has.add('loader-configurable', true);
Expand Down Expand Up @@ -1064,6 +1065,21 @@ declare const Packages: {} | undefined;

setGlobals = globalObjectGlobals;
}
else if (has('host-web-worker')) {
injectUrl = function (url: string, callback: (node?: HTMLScriptElement) => void, module: DojoLoader.Module,
parent?: DojoLoader.Module): void {

try {
importScripts(url);
}
catch (e) {
reportModuleLoadError(parent, module, url);
}
callback();
};

setGlobals = globalObjectGlobals;
}
else {
throw new Error('Unsupported platform');
}
Expand Down
1 change: 1 addition & 0 deletions tests/functional/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import './crossOrigin';
import './csp';
import './scriptConfigReading';
import './shimAmdLoading';
import './webworkerAmd';
import './require/require';
15 changes: 15 additions & 0 deletions tests/functional/webworkerAmd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as assert from 'intern/chai!assert';
import * as registerSuite from 'intern!object';
import executeTest from './executeTest';

const AMD_APP_MESSAGE = 'Message from AMD app.';

registerSuite({
name: 'AMD loading in web worker',

'basic loading'(this: any) {
return executeTest(this, './webworkerBasic.html', function (results: any) {
assert.strictEqual(results.message, AMD_APP_MESSAGE);
});
}
});
21 changes: 21 additions & 0 deletions tests/functional/webworkerBasic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
if (window.Worker) {
const worker = new Worker('worker.js');

worker.onmessage = function (e) {
window.loaderTestResults = e.data;
}

worker.postMessage('start');
}
else {
console.error('does not support web workers');
}
</script>
</body>
</html>
28 changes: 28 additions & 0 deletions tests/functional/worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
onmessage = function (e) {
try {
/* load the loader */
importScripts('../../src/loader.js');

require.config({
packages: [
{ name: 'amdApp', location: './amdApp' }
]
});

require([
'amdApp/app'
], function (app) {
/* post message back with the results */
(<any> postMessage)({
message: app.getMessage()
});
});
}
catch (e) {
(<any> postMessage)({
message: e.message,
status: 'fail'
});
throw e;
}
};