| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- //-------------------------------------------------------------------------------------------------------
- // Copyright (C) Microsoft. All rights reserved.
- // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
- //-------------------------------------------------------------------------------------------------------
- function check(value, expected) {
- if (value !== expected) {
- throw new Error("Test failed");
- }
- }
- function f1()
- {
- this.x1 = "hello";
- }
- f1.apply();
- check(x1, "hello");
- x1 = 0;
- f1.apply(null);
- check(x1, "hello");
- x1 = 0;
- f1.apply(undefined);
- check(x1, "hello");
- var o = new Object();
- x1 = 0;
- f1.apply(o);
- check(x1, 0);
- check(o.x1, "hello");
- function f2(a)
- {
- this.x2 = a;
- }
- x2 = 0;
- f2.apply();
- check(x2, undefined);
- x2 = 0;
- f2.apply(null);
- check(x2, undefined);
- x2 = 0;
- f2.apply(undefined);
- check(x2, undefined);
- x2 = 0;
- f2.apply(o);
- check(x2, 0);
- check(o.x2, undefined);
- x2 = 0;
- f2.apply(null, ["world"]);
- check(x2, "world");
- x2 = 0;
- f2.apply(undefined, ["world"]);
- check(x2, "world");
- x2 = 0;
- f2.apply(o, ["world"]);
- check(x2, 0);
- check(o.x2, "world");
- function blah()
- {
- this.construct.apply(this, arguments);
- return new Object();
- }
- function blah2()
- {
- try
- {
- this.construct.apply(this, arguments);
- }
- catch (e)
- {
- }
- return new Object();
- }
- blah.prototype.construct = function(x, y)
- {
- this.a = x;
- this.b = y;
- }
- blah2.prototype.construct = function(x, y)
- {
- this.a = x;
- this.b = y;
- }
- var o = new blah(1, 2);
- check(o.a, undefined);
- check(o.b, undefined);
- o = new blah2(1, 2);
- check(o.a, undefined);
- check(o.b, undefined);
- function f() {}
- f.apply({},{});
- f.apply({},{length:null});
- f.apply({},{length:undefined});
- f.apply({},{length:0.5});
- print("pass");
|