Browse Source

add a few test cases for testing uncommon eval/bind/call/apply cases, like using bind() on bind itself

pull/2/head
Sami Vaarala 11 years ago
parent
commit
889bfa934f
  1. 36
      ecmascript-testcases/test-dev-bind-bind.js
  2. 32
      ecmascript-testcases/test-dev-bind-call-apply.js
  3. 34
      ecmascript-testcases/test-dev-eval-call-apply.js

36
ecmascript-testcases/test-dev-bind-bind.js

@ -0,0 +1,36 @@
/*
* Test that bind() can also be used with bind().
*/
/*===
foo this: [object global] args: foo bar quux baz
foo this: mythis args: a b c d
foo this: mythis args: a b c final
===*/
function foo(x,y,z,w) {
print('foo', 'this:', this, 'args:', x, y, z, w);
}
function test() {
var f, g, h;
// plain call
foo('foo', 'bar', 'quux', 'baz');
// bound call
f = foo.bind('mythis', 'a', 'b', 'c', 'd');
f();
// bind bind() so that when the result is called, the resulting
// bind call arguments look like the "f = foo.bind" above
g = Function.prototype.bind.bind(foo, 'mythis', 'a', 'b', 'c'); // leave last arg unbound
h = g('final'); // give last arg
h();
}
try {
test();
} catch (e) {
print(e);
}

32
ecmascript-testcases/test-dev-bind-call-apply.js

@ -0,0 +1,32 @@
/*
* Use bind() indirectly with call() or apply().
*/
/*===
apply
foo this: boundthis args: argx argy argz undefined
call
foo this: boundthis args: argx argy argz undefined
===*/
function foo(x,y,z,w) {
print('foo', 'this:', this, 'args:', x, y, z, w);
}
function test() {
var f1, f2;
print('apply');
f1 = foo.bind.apply(foo, [ 'boundthis', 'argx', 'argy', 'argz' ]);
f1();
print('call');
f2 = foo.bind.call(foo, 'boundthis', 'argx', 'argy', 'argz');
f2();
}
try {
test();
} catch (e) {
print(e);
}

34
ecmascript-testcases/test-dev-eval-call-apply.js

@ -0,0 +1,34 @@
/*
* Use eval() indirectly with call() or apply().
*/
/*===
apply
hello from eval!
call
hello from eval!
bind
hello from eval!
===*/
function test() {
var code = 'print("hello from eval!");';
var f;
print('apply');
eval.apply(this, [ code ]);
print('call');
eval.call(this, code);
/* Also test indirect use of eval through bind() */
print('bind');
f = eval.bind(this, code);
f();
}
try {
test();
} catch (e) {
print(e);
}
Loading…
Cancel
Save