Skip to content

Commit

Permalink
Support configuring the monitor's base policy
Browse files Browse the repository at this point in the history
  • Loading branch information
lawnsea committed May 5, 2012
1 parent 1003df9 commit 25d9c6e
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/kernel.js
@@ -1,7 +1,7 @@
define([
'treehouse/sandbox', 'treehouse/util'
'treehouse/sandbox', 'treehouse/util', 'treehouse/policy/base-monitor'
],
function(Sandbox, util) {
function(Sandbox, util, basePolicy) {
var sandboxes = {};
var sandboxIndex = 0;
var messageHandlers = {};
Expand Down Expand Up @@ -69,8 +69,29 @@ function(Sandbox, util) {
}
};

// Adapted from Andrew Dupont's implementation
// http://andrewdupont.net/2009/08/28/deep-extending-objects-in-javascript/
function deepExtend(destination, source) {
for (var property in source) {
if (typeof source[property] === "object" &&
source[property] !== null ) {
destination[property] = destination[property] || {};
deepExtend(destination[property], source[property]);
} else {
destination[property] = source[property];
}
}
return destination;
}

function setPolicy(newPolicy, currentPolicy) {
deepExtend(currentPolicy, newPolicy);
}

function initialize(config) {
config = config || {};
config.policy = config.policy || {};

// TODO: handle scripts in HEAD; probably need to just prefix
// traversals with 'body' or 'head'
var guestScripts = Array.prototype.slice.apply(
Expand All @@ -83,6 +104,8 @@ function(Sandbox, util) {
var toRemove = [];
var i, j, k, len, worker, selector, script;

setPolicy(config.policy, basePolicy);

policyScripts.forEach(function (script, scriptIndex, guestScripts) {
var name = script.getAttribute('data-treehouse-sandbox-name') ||
'sandbox' + sandboxIndex;
Expand Down

0 comments on commit 25d9c6e

Please sign in to comment.