Skip to content

Commit

Permalink
Remove window dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilk committed Aug 26, 2012
1 parent 54bae4a commit 771881a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
10 changes: 5 additions & 5 deletions src/Core/CoreScript/BCL/Delegate.js
Expand Up @@ -99,22 +99,22 @@ ss.Delegate.createExport = function#? DEBUG Delegate$createExport##(delegate, mu
// Generate a unique name if one is not specified
name = name || '__' + (new Date()).valueOf();

// Exported delegates go on window (so they are callable using a simple identifier).
// Exported delegates go on global object (so they are callable using a simple identifier).

// Multi-use delegates are exported directly; for the rest a stub is exported, and the stub
// first deletes, and then invokes the actual delegate.
window[name] = multiUse ? delegate : function() {
try { delete window[name]; } catch(e) { window[name] = undefined; }
global[name] = multiUse ? delegate : function() {
try { delete global[name]; } catch(e) { global[name] = undefined; }
delegate.apply(null, arguments);
};

return name;
}

ss.Delegate.deleteExport = function#? DEBUG Delegate$deleteExport##(name) {
delete window[name];
delete global[name];
}

ss.Delegate.clearExport = function#? DEBUG Delegate$clearExport##(name) {
window[name] = ss.Delegate.empty;
global[name] = ss.Delegate.empty;
}
30 changes: 13 additions & 17 deletions src/Core/CoreScript/TypeSystem/Type.js
@@ -1,47 +1,43 @@
///////////////////////////////////////////////////////////////////////////////
// Type System Implementation

window.Type = Function;
global.Type = Function;
Type.__typeName = 'Type';

window.__Namespace = function(name) {
var __namespaces = {};
var __rootNamespaces = [];

function ns(name) {
this.__typeName = name;
}
__Namespace.prototype = {
ns.prototype = {
__namespace: true,
getName: function() {
return this.__typeName;
}
}

Type.registerNamespace = function#? DEBUG Type$registerNamespace##(name) {
if (!window.__namespaces) {
window.__namespaces = {};
}
if (!window.__rootNamespaces) {
window.__rootNamespaces = [];
}

if (window.__namespaces[name]) {
if (__namespaces[name]) {
return;
}

var ns = window;
var nsi = global;
var nameParts = name.split('.');

for (var i = 0; i < nameParts.length; i++) {
var part = nameParts[i];
var nso = ns[part];
var nso = nsi[part];
if (!nso) {
ns[part] = nso = new __Namespace(nameParts.slice(0, i + 1).join('.'));
nsi[part] = nso = new ns(nameParts.slice(0, i + 1).join('.'));
if (i == 0) {
window.__rootNamespaces.add(nso);
__rootNamespaces.add(nso);
}
}
ns = nso;
nsi = nso;
}

window.__namespaces[name] = ns;
__namespaces[name] = nsi;
}

Type.prototype.registerClass = function#? DEBUG Type$registerClass##(name, baseType, interfaceType) {
Expand Down
14 changes: 7 additions & 7 deletions src/Core/CoreScript/mscorlib.js
Expand Up @@ -2,27 +2,26 @@
//! More information at http://projects.nikhilk.net/ScriptSharp
//!

(function () {
window.ss = {
(function(global) {
global.ss = {
version: '0.7.6.0',

isUndefined: function (o) {
isUndefined: function(o) {
return (o === undefined);
},

isNull: function (o) {
isNull: function(o) {
return (o === null);
},

isNullOrUndefined: function (o) {
isNullOrUndefined: function(o) {
return (o === null) || (o === undefined);
},

isValue: function (o) {
isValue: function(o) {
return (o !== null) && (o !== undefined);
}
};
})();

#include "Extensions\Object.js"

Expand Down Expand Up @@ -69,3 +68,4 @@
#include "BCL\Task.js"

#include "BCL\App.js"
})(this);

0 comments on commit 771881a

Please sign in to comment.