Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

global context test passes

  • Loading branch information...
commit 9629b3718f569c280f5ed3c7934d2c4b0bf444b4 1 parent d743598
@substack authored
Showing with 14 additions and 6 deletions.
  1. +7 −2 index.js
  2. +1 −1  package.json
  3. +6 −3 test/global.js
View
9 index.js
@@ -94,6 +94,12 @@ Stack.prototype.compile = function (context, opts) {
: apply(that[fn], that, args)
;
}
+ else if (opts.hasOwnProperty('global')) {
+ res = fn.apply
+ ? fn.apply(opts.global, args)
+ : apply(fn, opts.global, args)
+ ;
+ }
else {
res = fn.apply
? fn.apply(that, args)
@@ -216,7 +222,6 @@ Stack.prototype.compile = function (context, opts) {
if (node.value[0][0] === 'name') {
fn = node.value[0][1];
- that = null;
}
else if (node.value[0][0] === 'dot') {
fn = json.stringify(node.value[0][node.value[0].length-1]);
@@ -235,8 +240,8 @@ Stack.prototype.compile = function (context, opts) {
}
else {
fn = burrito(node.value[0], wrapper_).replace(/;$/, '');
- that = null;
}
+
var args = burrito([ 'array', node.value[1] ], wrapper_)
.replace(/;$/, '');
node.wrap(
View
2  package.json
@@ -1,7 +1,7 @@
{
"name" : "stackedy",
"description" : "Roll your own stack traces and control program execution through AST manipulation",
- "version" : "0.1.3",
+ "version" : "0.1.4",
"repository" : {
"type" : "git",
"url" : "git://github.com/substack/node-stackedy.git"
View
9 test/global.js
@@ -9,10 +9,12 @@ test('setTimeout context for IE9 must be window', function (t) {
var global = {};
var to = function () {
- return setTimeout.apply(this, arguments);
+ t.fail('should have been called with .apply()')
};
+
to.apply = function () {
- t.equal(this, global);
+ t.equal(arguments[0], global);
+ return setTimeout.apply.apply(setTimeout, arguments);
};
var context = {
@@ -20,7 +22,8 @@ test('setTimeout context for IE9 must be window', function (t) {
t.equal(n, 5);
t.end();
},
- setTimeout : to
+ setTimeout : to,
+ console : console
};
var stack = stackedy(src).run(context, {
Please sign in to comment.
Something went wrong with that request. Please try again.