Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#40 Loader with Nashorn #62

Merged
merged 6 commits into from Apr 8, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/loader.ts
@@ -1,5 +1,5 @@
'use strict';
(function (): void {
(function (args?: string[]): void {
const globalObject: any = Function('return this')();
const EXECUTING: string = 'executing';
const ABORT_EXECUTION: Object = {};
Expand Down Expand Up @@ -161,6 +161,7 @@

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('debug', true);

// IE9 will process multiple scripts at once before firing their respective onload events, so some extra work
Expand Down Expand Up @@ -834,6 +835,11 @@
};
}

let globalObjectGlobals = function (require: DojoLoader.Require, define: DojoLoader.Define): void {
globalObject.require = require;
globalObject.define = define;
};

if (has('host-node')) {
loadNodeModule = (moduleId: string, parent?: DojoLoader.Module): any => {
let module: any = require('module');
Expand Down Expand Up @@ -942,10 +948,17 @@
document.head.appendChild(node);
};

setGlobals = function (require: DojoLoader.RootRequire, define: DojoLoader.Define): void {
globalObject.require = require;
globalObject.define = define;
setGlobals = globalObjectGlobals;
}
else if (has('host-nashorn')) {
injectUrl = function (url: string, callback: (node?: HTMLScriptElement) => void, module: DojoLoader.Module,
parent?: DojoLoader.Module): void {

load(url);
callback();
};

setGlobals = globalObjectGlobals;
}
else {
throw new Error('Unsupported platform');
Expand Down Expand Up @@ -1087,4 +1100,7 @@
});

setGlobals(requireModule, define);
})();
if (has('host-nashorn') && args[0]) {
load(args[0]);
}
})((typeof Packages !== 'undefined' ? Array.prototype.slice.call(arguments, 0) : []));
3 changes: 3 additions & 0 deletions tests/typings/nashorn/nashorn.d.ts
@@ -0,0 +1,3 @@
declare var arguments: any;
declare var load: any;
declare var Packages: any;
1 change: 1 addition & 0 deletions tests/typings/tsd.d.ts
@@ -1,5 +1,6 @@
/// <reference path="intern/intern.d.ts" />
/// <reference path="node/node.d.ts" />
/// <reference path="nashorn/nashorn.d.ts" />

declare module 'intern/dojo/Promise' {
import Promise = require('dojo/Promise');
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Expand Up @@ -41,6 +41,7 @@
"./tests/typings/dojo2/dojo.d.ts",
"./tests/typings/intern/intern.d.ts",
"./tests/typings/leadfoot/leadfoot.d.ts",
"./tests/typings/nashorn/nashorn.d.ts",
"./tests/typings/node/node.d.ts",
"./tests/typings/tsd.d.ts",
"./tests/unit/all.ts",
Expand Down