Home | History | Annotate | Download | only in es6
      1 // Copyright 2015 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 var object = {};
      6 var global = this;
      7 var call = Function.call.bind(Function.call);
      8 
      9 var globalSloppyArrow = () => this;
     10 var globalStrictArrow = () => { "use strict"; return this; };
     11 var globalSloppyArrowEval = (s) => eval(s);
     12 var globalStrictArrowEval = (s) => { "use strict"; return eval(s); };
     13 
     14 var sloppyFunctionArrow = function() {
     15   return (() => this)();
     16 };
     17 var strictFunctionArrow = function() {
     18   "use strict";
     19   return (() => this)();
     20 };
     21 var sloppyFunctionEvalArrow = function() {
     22   return eval("(() => this)()");
     23 };
     24 var strictFunctionEvalArrow = function() {
     25   "use strict";
     26   return eval("(() => this)()");
     27 };
     28 var sloppyFunctionArrowEval = function(s) {
     29   return (() => eval(s))();
     30 };
     31 var strictFunctionArrowEval = function(s) {
     32   "use strict";
     33   return (() => eval(s))();
     34 };
     35 
     36 var withObject = { 'this': object }
     37 var arrowInsideWith, arrowInsideWithEval;
     38 with (withObject) {
     39   arrowInsideWith = () => this;
     40   arrowInsideWithEval = (s) => eval(s);
     41 }
     42 
     43 assertEquals(global, call(globalSloppyArrow, object));
     44 assertEquals(global, call(globalStrictArrow, object));
     45 assertEquals(global, call(globalSloppyArrowEval, object, "this"));
     46 assertEquals(global, call(globalStrictArrowEval, object, "this"));
     47 assertEquals(global, call(globalSloppyArrowEval, object, "(() => this)()"));
     48 assertEquals(global, call(globalStrictArrowEval, object, "(() => this)()"));
     49 
     50 assertEquals(object, call(sloppyFunctionArrow, object));
     51 assertEquals(global, call(sloppyFunctionArrow, undefined));
     52 assertEquals(object, call(strictFunctionArrow, object));
     53 assertEquals(undefined, call(strictFunctionArrow, undefined));
     54 
     55 assertEquals(object, call(sloppyFunctionEvalArrow, object));
     56 assertEquals(global, call(sloppyFunctionEvalArrow, undefined));
     57 assertEquals(object, call(strictFunctionEvalArrow, object));
     58 assertEquals(undefined, call(strictFunctionEvalArrow, undefined));
     59 
     60 assertEquals(object, call(sloppyFunctionArrowEval, object, "this"));
     61 assertEquals(global, call(sloppyFunctionArrowEval, undefined, "this"));
     62 assertEquals(object, call(strictFunctionArrowEval, object, "this"));
     63 assertEquals(undefined, call(strictFunctionArrowEval, undefined, "this"));
     64 
     65 assertEquals(object,
     66              call(sloppyFunctionArrowEval, object, "(() => this)()"));
     67 assertEquals(global,
     68              call(sloppyFunctionArrowEval, undefined, "(() => this)()"));
     69 assertEquals(object,
     70              call(strictFunctionArrowEval, object, "(() => this)()"));
     71 assertEquals(undefined,
     72              call(strictFunctionArrowEval, undefined, "(() => this)()"));
     73 
     74 assertEquals(global, call(arrowInsideWith, undefined));
     75 assertEquals(global, call(arrowInsideWith, object));
     76 assertEquals(global, call(arrowInsideWithEval, undefined, "this"));
     77 assertEquals(global, call(arrowInsideWithEval, object, "this"));
     78 assertEquals(global, call(arrowInsideWithEval, undefined, "(() => this)()"));
     79 assertEquals(global, call(arrowInsideWithEval, object, "(() => this)()"));
     80