Skip to content

Commit

Permalink
csp build global support
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Dec 10, 2015
1 parent bf09153 commit 2863a79
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
15 changes: 15 additions & 0 deletions lib/global-helpers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
hook('reduceRegister_', function(reduceRegister) {
return function(load, register) {
if (register || !load.metadata.exports)
return reduceRegister.call(this, load, register);

load.metadata.format = 'global';
var entry = load.metadata.entry = createEntry();
entry.deps = load.metadata.deps;
var globalValue = readMemberExpression(load.metadata.exports, __global);
entry.execute = function() {
return globalValue;
};
};
});

hookConstructor(function(constructor) {
return function() {
var loader = this;
Expand Down
14 changes: 0 additions & 14 deletions lib/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,6 @@
*/
var __globalName = typeof self != 'undefined' ? 'self' : 'global';

hook('reduceRegister_', function(reduceRegister) {
return function(load, register) {
if (register)
return reduceRegister.call(this, load, register);

load.metadata.format = 'global';
var entry = load.metadata.entry = createEntry();
var globalValue = readMemberExpression(load.metadata.exports, __global);
entry.execute = function() {
return globalValue;
};
};
});

hook('fetch', function(fetch) {
return function(load) {
if (load.metadata.exports && !load.metadata.format)
Expand Down
2 changes: 1 addition & 1 deletion lib/scriptLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@

// if nothing registered, then something went wrong
if (!load.metadata.entry && !load.metadata.bundle)
reject(new Error(load.name + ' did not call System.register or AMD define'));
reject(new Error(load.name + ' did not call System.register or AMD define. If loading a global module configure the global name via the meta exports property for script injection support.'));

resolve('');
}
Expand Down
14 changes: 14 additions & 0 deletions test/test-csp.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,20 @@ <h2 id="qunit-userAgent"></h2>
ok(e.toString().indexOf('did not call System.register or AMD define') != -1);
start();
});
});

asyncTest('Loading a global with exports defined', function() {
System.config({
meta: {
'tests/global-single.js': {
exports: 'foo'
}
}
});
System['import']('tests/global-single.js').then(function(m) {
ok(m == 'bar');
start();
});
})

asyncTest('Importing a script with wrong integrity fails', function() {
Expand Down

0 comments on commit 2863a79

Please sign in to comment.