Comparing version 0.4.10 to 0.4.11
{ | ||
"name": "aether", | ||
"version": "0.4.10", | ||
"version": "0.4.11", | ||
"homepage": "https://github.com/codecombat/aether", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -306,2 +306,6 @@ (function() { | ||
Aether.prototype.createThread = function(fx) { | ||
return interpreter.createThread(this, fx); | ||
}; | ||
Aether.prototype.updateProblemContext = function(problemContext) { | ||
@@ -308,0 +312,0 @@ return this.options.problemContext = problemContext; |
(function() { | ||
var addedGlobals, isStatement, updateState, _, _ref, _ref1, _ref2; | ||
var addedGlobals, isStatement, makeYieldFilter, updateState, upgradeEvaluator, _, _ref, _ref1, _ref2; | ||
@@ -116,3 +116,3 @@ _ = (_ref = (_ref1 = (_ref2 = typeof window !== "undefined" && window !== null ? window._ : void 0) != null ? _ref2 : typeof self !== "undefined" && self !== null ? self._ : void 0) != null ? _ref1 : typeof global !== "undefined" && global !== null ? global._ : void 0) != null ? _ref : require('lodash'); | ||
module.exports.createFunction = function(aether, code) { | ||
var engine, esper, executionCount, fx, fxName, messWithLoops, name, state, x, _i, _len, _ref3, _ref4, _ref5, _ref6; | ||
var engine, esper, fx, fxName, messWithLoops, name, state, x, _i, _len, _ref3, _ref4, _ref5, _ref6; | ||
esper = (_ref3 = (_ref4 = (_ref5 = typeof window !== "undefined" && window !== null ? window.esper : void 0) != null ? _ref5 : typeof self !== "undefined" && self !== null ? self.esper : void 0) != null ? _ref4 : typeof global !== "undefined" && global !== null ? global.esper : void 0) != null ? _ref3 : require('esper.js'); | ||
@@ -124,6 +124,9 @@ state = {}; | ||
} | ||
engine = new esper.Engine({ | ||
strict: true, | ||
foreignObjectMode: 'smart' | ||
}); | ||
if (!aether.esperEngine) { | ||
aether.esperEngine = new esper.Engine({ | ||
strict: true, | ||
foreignObjectMode: 'smart' | ||
}); | ||
} | ||
engine = aether.esperEngine; | ||
fxName = aether.options.functionName || 'foo'; | ||
@@ -139,49 +142,6 @@ if (aether.language.injectCode != null) { | ||
engine.evalASTSync(aether.ast); | ||
executionCount = 0; | ||
engine.evaluator.instrument = function() { | ||
if (++executionCount > aether.options.executionLimit) { | ||
throw new TypeError('Statement execution limit reached'); | ||
} | ||
return updateState(aether, engine.evaluator); | ||
}; | ||
upgradeEvaluator(aether, engine.evaluator); | ||
x = 0; | ||
if (aether.options.yieldConditionally) { | ||
fx = engine.fetchFunction(fxName, function(engine) { | ||
var frame_stack, newMark, top, yieldValue; | ||
frame_stack = engine.evaluator.frames; | ||
top = frame_stack[0]; | ||
if (top.type === 'loop') { | ||
if (frame_stack[1].ast.type === 'WhileStatement' && frame_stack[1].ast.test.type === 'Literal') { | ||
if (!top.marked) { | ||
top.marked = true; | ||
if (aether.whileLoopMarker) { | ||
top.mark = aether.whileLoopMarker(); | ||
} | ||
} else if (top.ast == null) { | ||
if (!top.didYield) { | ||
if (!aether.whileLoopMarker || aether.whileLoopMarker() === top.mark) { | ||
top.didYield = false; | ||
return true; | ||
} else { | ||
newMark = aether.whileLoopMarker(); | ||
top.mark = newMark; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
yieldValue = aether._shouldYield; | ||
if (!yieldValue) { | ||
return false; | ||
} | ||
aether._shouldYield = false; | ||
if (aether.onAetherYield) { | ||
aether.onAetherYield(yieldValue); | ||
} | ||
aether._shouldYield = false; | ||
if (frame_stack[1].type === 'loop') { | ||
frame_stack[1].didYield = true; | ||
} | ||
return yieldValue; | ||
}); | ||
fx = engine.fetchFunction(fxName, makeYieldFilter(aether)); | ||
} else if (aether.options.yieldAutomatically) { | ||
@@ -197,2 +157,55 @@ fx = engine.fetchFunction(fxName, function(engine) { | ||
makeYieldFilter = function(aether) { | ||
return function(engine) { | ||
var frame_stack, newMark, top; | ||
frame_stack = engine.evaluator.frames; | ||
top = frame_stack[0]; | ||
if (top.type === 'loop') { | ||
if (frame_stack[1].ast.type === 'WhileStatement' && frame_stack[1].ast.test.type === 'Literal') { | ||
if (!top.marked) { | ||
top.marked = true; | ||
if (aether.whileLoopMarker) { | ||
top.mark = aether.whileLoopMarker(); | ||
} | ||
} else if (top.ast == null) { | ||
if (!top.didYield) { | ||
if (!aether.whileLoopMarker || aether.whileLoopMarker() === top.mark) { | ||
top.didYield = false; | ||
return true; | ||
} else { | ||
newMark = aether.whileLoopMarker(); | ||
top.mark = newMark; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return false; | ||
}; | ||
}; | ||
module.exports.createThread = function(aether, fx) { | ||
var Evaluator, engine, internalFx; | ||
internalFx = esper.Value.getBookmark(fx); | ||
engine = new esper.Engine(aether.esperEngine.options); | ||
Evaluator = aether.esperEngine.evaluator.constructor; | ||
engine.evaluator = new Evaluator(aether.esperEngine.realm, aether.esperEngine.evaluator.ast, aether.esperEngine.evaluator.frames[0].scope); | ||
engine.evaluator.frames = []; | ||
upgradeEvaluator(aether, engine.evaluator); | ||
return engine.makeFunctionFromClosure(internalFx, function() { | ||
return false; | ||
}); | ||
}; | ||
module.exports.upgradeEvaluator = upgradeEvaluator = function(aether, evaluator) { | ||
var executionCount; | ||
executionCount = 0; | ||
return evaluator.instrument = function() { | ||
if (++executionCount > aether.options.executionLimit) { | ||
throw new TypeError('Statement execution limit reached'); | ||
} | ||
return updateState(aether, evaluator); | ||
}; | ||
}; | ||
}).call(this); |
{ | ||
"name": "aether", | ||
"version": "0.4.10", | ||
"version": "0.4.11", | ||
"description": "Analyzes, instruments, and transpiles JS to help beginners.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
920160
23217