Skip to content

Instantly share code, notes, and snippets.

@aseemk
Created August 10, 2011 22:08
Show Gist options
  • Save aseemk/1138411 to your computer and use it in GitHub Desktop.
Save aseemk/1138411 to your computer and use it in GitHub Desktop.
Streamline bug: Function::apply(this, arguments) not handled
// arguments_.js
// Tests Streamline's ability to handle `arguments` objects which contain a
// Streamline (underscore) callback parameter.
var THIS = 'context';
var COOKIE = 'cookie'
var innerHasExited = false;
var outerHasExited = false;
function inner(cookie, _) {
if (this.toString() !== THIS) {
console.log('FAIL: `this` was not properly preserved: ' + this);
} else {
console.log('PASS: `this` was properly preserved.')
}
setTimeout(_, 500);
if (outerHasExited) {
console.log('FAIL: inner exiting after outer.');
} else {
console.log('PASS: inner exiting before outer.');
}
innerHasExited = true;
return cookie;
}
function outer(cookie, _) {
if (this.toString() !== THIS) {
console.log('FAIL: `this` was not properly preserved: ' + this);
} else {
console.log('PASS: `this` was properly preserved.')
}
// FAILS:
var result = inner.apply(this, arguments);
// PASSES:
//var result = inner.call(this, cookie, _);
if (!innerHasExited) {
console.log('FAIL: outer exiting before inner.');
} else {
console.log('PASS: outer exiting after inner.');
}
outerHasExited = true;
return result;
}
var context = {
runTest: outer,
toString: function () {
return THIS;
}
};
var future = context.runTest(COOKIE);
var result = future(_);
if (result !== COOKIE) {
console.log('FAIL: argument was not properly passed: ' + result);
} else {
console.log('PASS: argument was properly preserved.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment