Home | History | Annotate | Download | only in harmony
      1 // Copyright 2011 the V8 project authors. All rights reserved.
      2 // Redistribution and use in source and binary forms, with or without
      3 // modification, are permitted provided that the following conditions are
      4 // met:
      5 //
      6 //     * Redistributions of source code must retain the above copyright
      7 //       notice, this list of conditions and the following disclaimer.
      8 //     * Redistributions in binary form must reproduce the above
      9 //       copyright notice, this list of conditions and the following
     10 //       disclaimer in the documentation and/or other materials provided
     11 //       with the distribution.
     12 //     * Neither the name of Google Inc. nor the names of its
     13 //       contributors may be used to endorse or promote products derived
     14 //       from this software without specific prior written permission.
     15 //
     16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 
     28 // Flags: --harmony-proxies --allow-natives-syntax
     29 
     30 
     31 // TODO(neis): These tests are temporarily commented out because of ongoing
     32 // changes to the implementation of proxies.
     33 
     34 
     35 //// Ensures that checking the "length" property of a function proxy doesn't
     36 //// crash due to lack of a [[Get]] method.
     37 //var handler = {
     38 //  get : function(r, n) { return n == "length" ? 2 : undefined }
     39 //}
     40 //
     41 //
     42 //// Calling (call, Function.prototype.call, Function.prototype.apply,
     43 ////          Function.prototype.bind).
     44 //
     45 //var global_object = this
     46 //var receiver
     47 //
     48 //function TestCall(isStrict, callTrap) {
     49 //  assertEquals(42, callTrap(5, 37))
     50 //  assertSame(isStrict ? undefined : global_object, receiver)
     51 //
     52 //  var handler = {
     53 //    get: function(r, k) {
     54 //      return k == "length" ? 2 : Function.prototype[k]
     55 //    }
     56 //  }
     57 //  var f = Proxy.createFunction(handler, callTrap)
     58 //  var o = {f: f}
     59 //  global_object.f = f
     60 //
     61 //  receiver = 333
     62 //  assertEquals(42, f(11, 31))
     63 //  assertSame(isStrict ? undefined : global_object, receiver)
     64 //  receiver = 333
     65 //  assertEquals(42, o.f(10, 32))
     66 //  assertSame(o, receiver)
     67 //  receiver = 333
     68 //  assertEquals(42, o["f"](9, 33))
     69 //  assertSame(o, receiver)
     70 //  receiver = 333
     71 //  assertEquals(42, (1, o).f(8, 34))
     72 //  assertSame(o, receiver)
     73 //  receiver = 333
     74 //  assertEquals(42, (1, o)["f"](7, 35))
     75 //  assertSame(o, receiver)
     76 //  receiver = 333
     77 //  assertEquals(42, f.call(o, 32, 10))
     78 //  assertSame(o, receiver)
     79 //  receiver = 333
     80 //  assertEquals(42, f.call(undefined, 33, 9))
     81 //  assertSame(isStrict ? undefined : global_object, receiver)
     82 //  receiver = 333
     83 //  assertEquals(42, f.call(null, 33, 9))
     84 //  assertSame(isStrict ? null : global_object, receiver)
     85 //  receiver = 333
     86 //  assertEquals(44, f.call(2, 21, 23))
     87 //  assertSame(2, receiver.valueOf())
     88 //  receiver = 333
     89 //  assertEquals(42, Function.prototype.call.call(f, o, 20, 22))
     90 //  assertSame(o, receiver)
     91 //  receiver = 333
     92 //  assertEquals(43, Function.prototype.call.call(f, null, 20, 23))
     93 //  assertSame(isStrict ? null : global_object, receiver)
     94 //  assertEquals(44, Function.prototype.call.call(f, 2, 21, 23))
     95 //  assertEquals(2, receiver.valueOf())
     96 //  receiver = 333
     97 //  assertEquals(32, f.apply(o, [16, 16]))
     98 //  assertSame(o, receiver)
     99 //  receiver = 333
    100 //  assertEquals(32, Function.prototype.apply.call(f, o, [17, 15]))
    101 //  assertSame(o, receiver)
    102 //  receiver = 333
    103 //  assertEquals(42, %Call(f, o, 11, 31));
    104 //  assertSame(o, receiver)
    105 //  receiver = 333
    106 //  assertEquals(42, %Call(f, null, 11, 31));
    107 //  assertSame(isStrict ? null : global_object, receiver)
    108 //  receiver = 333
    109 //  assertEquals(42, %Apply(f, o, [11, 31], 0, 2))
    110 //  assertSame(o, receiver)
    111 //  receiver = 333
    112 //  assertEquals(42, %Apply(f, null, [11, 31], 0, 2))
    113 //  assertSame(isStrict ? null : global_object, receiver)
    114 //  receiver = 333
    115 //  assertEquals(42, %_Call(f, o, 11, 31))
    116 //  assertSame(o, receiver)
    117 //  receiver = 333
    118 //  assertEquals(42, %_Call(f, null, 11, 31))
    119 //  assertSame(isStrict ? null : global_object, receiver)
    120 //
    121 //  var ff = Function.prototype.bind.call(f, o, 12)
    122 //  assertTrue(ff.length <= 1)  // TODO(rossberg): Not spec'ed yet, be lax.
    123 //  receiver = 333
    124 //  assertEquals(42, ff(30))
    125 //  assertSame(o, receiver)
    126 //  receiver = 333
    127 //  assertEquals(33, Function.prototype.call.call(ff, {}, 21))
    128 //  assertSame(o, receiver)
    129 //  receiver = 333
    130 //  assertEquals(32, Function.prototype.apply.call(ff, {}, [20]))
    131 //  assertSame(o, receiver)
    132 //  receiver = 333
    133 //  assertEquals(23, %Call(ff, {}, 11));
    134 //  assertSame(o, receiver)
    135 //  receiver = 333
    136 //  assertEquals(23, %Call(ff, {}, 11, 3));
    137 //  assertSame(o, receiver)
    138 //  receiver = 333
    139 //  assertEquals(24, %Apply(ff, {}, [12, 13], 0, 1))
    140 //  assertSame(o, receiver)
    141 //  receiver = 333
    142 //  assertEquals(24, %Apply(ff, {}, [12, 13], 0, 2))
    143 //  assertSame(o, receiver)
    144 //  receiver = 333
    145 //  assertEquals(34, %_Call(ff, {}, 22))
    146 //  assertSame(o, receiver)
    147 //  receiver = 333
    148 //  assertEquals(34, %_Call(ff, {}, 22, 3))
    149 //  assertSame(o, receiver)
    150 //
    151 //  var fff = Function.prototype.bind.call(ff, o, 30)
    152 //  assertEquals(0, fff.length)
    153 //  receiver = 333
    154 //  assertEquals(42, fff())
    155 //  assertSame(o, receiver)
    156 //  receiver = 333
    157 //  assertEquals(42, Function.prototype.call.call(fff, {}))
    158 //  assertSame(o, receiver)
    159 //  receiver = 333
    160 //  assertEquals(42, Function.prototype.apply.call(fff, {}))
    161 //  assertSame(o, receiver)
    162 //  receiver = 333
    163 //  assertEquals(42, %Call(fff, {}));
    164 //  assertSame(o, receiver)
    165 //  receiver = 333
    166 //  assertEquals(42, %Call(fff, {}, 11, 3))
    167 //  assertSame(o, receiver)
    168 //  receiver = 333
    169 //  assertEquals(42, %Apply(fff, {}, [], 0, 0))
    170 //  assertSame(o, receiver)
    171 //  receiver = 333
    172 //  assertEquals(42, %Apply(fff, {}, [12, 13], 0, 0))
    173 //  assertSame(o, receiver)
    174 //  receiver = 333
    175 //  assertEquals(42, %Apply(fff, {}, [12, 13], 0, 2))
    176 //  assertSame(o, receiver)
    177 //  receiver = 333
    178 //  assertEquals(42, %_Call(fff, {}))
    179 //  assertSame(o, receiver)
    180 //  receiver = 333
    181 //  assertEquals(42, %_Call(fff, {}, 3, 4, 5))
    182 //  assertSame(o, receiver)
    183 //
    184 //  var f = CreateFrozen({}, callTrap)
    185 //  receiver = 333
    186 //  assertEquals(42, f(11, 31))
    187 //  assertSame(isStrict ? undefined : global_object, receiver)
    188 //  var o = {f: f}
    189 //  receiver = 333
    190 //  assertEquals(42, o.f(10, 32))
    191 //  assertSame(o, receiver)
    192 //  receiver = 333
    193 //  assertEquals(42, o["f"](9, 33))
    194 //  assertSame(o, receiver)
    195 //  receiver = 333
    196 //  assertEquals(42, (1, o).f(8, 34))
    197 //  assertSame(o, receiver)
    198 //  receiver = 333
    199 //  assertEquals(42, (1, o)["f"](7, 35))
    200 //  assertSame(o, receiver)
    201 //  receiver = 333
    202 //  assertEquals(42, Function.prototype.call.call(f, o, 20, 22))
    203 //  assertSame(o, receiver)
    204 //  receiver = 333
    205 //  assertEquals(32, Function.prototype.apply.call(f, o, [17, 15]))
    206 //  assertSame(o, receiver)
    207 //  receiver = 333
    208 //  assertEquals(23, %Call(f, o, 11, 12))
    209 //  assertSame(o, receiver)
    210 //  receiver = 333
    211 //  assertEquals(27, %Apply(f, o, [12, 13, 14], 1, 2))
    212 //  assertSame(o, receiver)
    213 //  receiver = 333
    214 //  assertEquals(42, %_Call(f, o, 18, 24))
    215 //  assertSame(o, receiver)
    216 //}
    217 //
    218 //TestCall(false, function(x, y) {
    219 //  receiver = this
    220 //  return x + y
    221 //})
    222 //
    223 //TestCall(true, function(x, y) {
    224 //  "use strict"
    225 //  receiver = this
    226 //  return x + y
    227 //})
    228 //
    229 //TestCall(false, function() {
    230 //  receiver = this
    231 //  return arguments[0] + arguments[1]
    232 //})
    233 //
    234 //TestCall(false, Proxy.createFunction(handler, function(x, y) {
    235 //  receiver = this
    236 //  return x + y
    237 //}))
    238 //
    239 //TestCall(true, Proxy.createFunction(handler, function(x, y) {
    240 //  "use strict"
    241 //  receiver = this
    242 //  return x + y
    243 //}))
    244 //
    245 //TestCall(false, CreateFrozen(handler, function(x, y) {
    246 //  receiver = this
    247 //  return x + y
    248 //}))
    249 //
    250 //
    251 //
    252 //// Using intrinsics as call traps.
    253 //
    254 //function TestCallIntrinsic(type, callTrap) {
    255 //  var f = Proxy.createFunction({}, callTrap)
    256 //  var x = f()
    257 //  assertTrue(typeof x == type)
    258 //}
    259 //
    260 //TestCallIntrinsic("boolean", Boolean)
    261 //TestCallIntrinsic("number", Number)
    262 //TestCallIntrinsic("string", String)
    263 //TestCallIntrinsic("object", Object)
    264 //TestCallIntrinsic("function", Function)
    265 //
    266 //
    267 //
    268 //// Throwing from call trap.
    269 //
    270 //function TestCallThrow(callTrap) {
    271 //  var f = Proxy.createFunction({}, callTrap)
    272 //  assertThrows(function(){ f(11) }, "myexn")
    273 //  assertThrows(function(){ ({x: f}).x(11) }, "myexn")
    274 //  assertThrows(function(){ ({x: f})["x"](11) }, "myexn")
    275 //  assertThrows(function(){ Function.prototype.call.call(f, {}, 2) }, "myexn")
    276 //  assertThrows(function(){ Function.prototype.apply.call(f, {}, [1]) }, "myexn")
    277 //  assertThrows(function(){ %Call(f, {}) }, "myexn")
    278 //  assertThrows(function(){ %Call(f, {}, 1, 2) }, "myexn")
    279 //  assertThrows(function(){ %Apply({}, f, [], 3, 0) }, "myexn")
    280 //  assertThrows(function(){ %Apply({}, f, [3, 4], 0, 1) }, "myexn")
    281 //  assertThrows(function(){ %_Call(f, {}) }, "myexn")
    282 //  assertThrows(function(){ %_Call(f, {}, 1, 2) }, "myexn")
    283 //
    284 //  var f = CreateFrozen({}, callTrap)
    285 //  assertThrows(function(){ f(11) }, "myexn")
    286 //  assertThrows(function(){ ({x: f}).x(11) }, "myexn")
    287 //  assertThrows(function(){ ({x: f})["x"](11) }, "myexn")
    288 //  assertThrows(function(){ Function.prototype.call.call(f, {}, 2) }, "myexn")
    289 //  assertThrows(function(){ Function.prototype.apply.call(f, {}, [1]) }, "myexn")
    290 //  assertThrows(function(){ %Call(f, {}) }, "myexn")
    291 //  assertThrows(function(){ %Call(f, {}, 1, 2) }, "myexn")
    292 //  assertThrows(function(){ %Apply({}, f, [], 3, 0) }, "myexn")
    293 //  assertThrows(function(){ %Apply({}, f, [3, 4], 0, 1) }, "myexn")
    294 //  assertThrows(function(){ %_Call(f, {}) }, "myexn")
    295 //  assertThrows(function(){ %_Call(f, {}, 1, 2) }, "myexn")
    296 //}
    297 //
    298 //TestCallThrow(function() { throw "myexn" })
    299 //TestCallThrow(Proxy.createFunction({}, function() { throw "myexn" }))
    300 //TestCallThrow(CreateFrozen({}, function() { throw "myexn" }))
    301 //
    302 //
    303 //
    304 //// Construction (new).
    305 //
    306 //var prototype = {myprop: 0}
    307 //var receiver
    308 //
    309 //var handlerWithPrototype = {
    310 //  fix: function() { return { prototype: { value: prototype } }; },
    311 //  get: function(r, n) {
    312 //    if (n == "length") return 2;
    313 //    assertEquals("prototype", n);
    314 //    return prototype;
    315 //  }
    316 //}
    317 //
    318 //var handlerSansPrototype = {
    319 //  fix: function() { return { length: { value: 2 } } },
    320 //  get: function(r, n) {
    321 //    if (n == "length") return 2;
    322 //    assertEquals("prototype", n);
    323 //    return undefined;
    324 //  }
    325 //}
    326 //
    327 //function ReturnUndef(x, y) {
    328 //  "use strict";
    329 //  receiver = this;
    330 //  this.sum = x + y;
    331 //}
    332 //
    333 //function ReturnThis(x, y) {
    334 //  "use strict";
    335 //  receiver = this;
    336 //  this.sum = x + y;
    337 //  return this;
    338 //}
    339 //
    340 //function ReturnNew(x, y) {
    341 //  "use strict";
    342 //  receiver = this;
    343 //  return {sum: x + y};
    344 //}
    345 //
    346 //function ReturnNewWithProto(x, y) {
    347 //  "use strict";
    348 //  receiver = this;
    349 //  var result = Object.create(prototype);
    350 //  result.sum = x + y;
    351 //  return result;
    352 //}
    353 //
    354 //function TestConstruct(proto, constructTrap) {
    355 //  TestConstruct2(proto, constructTrap, handlerWithPrototype)
    356 //  TestConstruct2(proto, constructTrap, handlerSansPrototype)
    357 //}
    358 //
    359 //function TestConstruct2(proto, constructTrap, handler) {
    360 //  var f = Proxy.createFunction(handler, function() {}, constructTrap)
    361 //  var o = new f(11, 31)
    362 //  assertEquals(undefined, receiver)
    363 //  assertEquals(42, o.sum)
    364 //  assertSame(proto, Object.getPrototypeOf(o))
    365 //
    366 //  var f = CreateFrozen(handler, function() {}, constructTrap)
    367 //  var o = new f(11, 32)
    368 //  assertEquals(undefined, receiver)
    369 //  assertEquals(43, o.sum)
    370 //  assertSame(proto, Object.getPrototypeOf(o))
    371 //}
    372 //
    373 //TestConstruct(Object.prototype, ReturnNew)
    374 //TestConstruct(prototype, ReturnNewWithProto)
    375 //
    376 //TestConstruct(Object.prototype, Proxy.createFunction(handler, ReturnNew))
    377 //TestConstruct(prototype, Proxy.createFunction(handler, ReturnNewWithProto))
    378 //
    379 //TestConstruct(Object.prototype, CreateFrozen(handler, ReturnNew))
    380 //TestConstruct(prototype, CreateFrozen(handler, ReturnNewWithProto))
    381 //
    382 //
    383 //
    384 //// Construction with derived construct trap.
    385 //
    386 //function TestConstructFromCall(proto, returnsThis, callTrap) {
    387 //  TestConstructFromCall2(prototype, returnsThis, callTrap, handlerWithPrototype)
    388 //  TestConstructFromCall2(proto, returnsThis, callTrap, handlerSansPrototype)
    389 //}
    390 //
    391 //function TestConstructFromCall2(proto, returnsThis, callTrap, handler) {
    392 //  // TODO(rossberg): handling of prototype for derived construct trap will be
    393 //  // fixed in a separate change. Commenting out checks below for now.
    394 //  var f = Proxy.createFunction(handler, callTrap)
    395 //  var o = new f(11, 31)
    396 //  if (returnsThis) assertEquals(o, receiver)
    397 //  assertEquals(42, o.sum)
    398 //  // assertSame(proto, Object.getPrototypeOf(o))
    399 //
    400 //  var g = CreateFrozen(handler, callTrap)
    401 //  // assertSame(f.prototype, g.prototype)
    402 //  var o = new g(11, 32)
    403 //  if (returnsThis) assertEquals(o, receiver)
    404 //  assertEquals(43, o.sum)
    405 //  // assertSame(proto, Object.getPrototypeOf(o))
    406 //}
    407 //
    408 //TestConstructFromCall(Object.prototype, true, ReturnUndef)
    409 //TestConstructFromCall(Object.prototype, true, ReturnThis)
    410 //TestConstructFromCall(Object.prototype, false, ReturnNew)
    411 //TestConstructFromCall(prototype, false, ReturnNewWithProto)
    412 //
    413 //TestConstructFromCall(Object.prototype, true,
    414 //                      Proxy.createFunction(handler, ReturnUndef))
    415 //TestConstructFromCall(Object.prototype, true,
    416 //                      Proxy.createFunction(handler, ReturnThis))
    417 //TestConstructFromCall(Object.prototype, false,
    418 //                      Proxy.createFunction(handler, ReturnNew))
    419 //TestConstructFromCall(prototype, false,
    420 //                      Proxy.createFunction(handler, ReturnNewWithProto))
    421 //
    422 //TestConstructFromCall(Object.prototype, true, CreateFrozen({}, ReturnUndef))
    423 //TestConstructFromCall(Object.prototype, true, CreateFrozen({}, ReturnThis))
    424 //TestConstructFromCall(Object.prototype, false, CreateFrozen({}, ReturnNew))
    425 //TestConstructFromCall(prototype, false, CreateFrozen({}, ReturnNewWithProto))
    426 //
    427 //ReturnUndef.prototype = prototype
    428 //ReturnThis.prototype = prototype
    429 //ReturnNew.prototype = prototype
    430 //ReturnNewWithProto.prototype = prototype
    431 //
    432 //TestConstructFromCall(prototype, true, ReturnUndef)
    433 //TestConstructFromCall(prototype, true, ReturnThis)
    434 //TestConstructFromCall(Object.prototype, false, ReturnNew)
    435 //TestConstructFromCall(prototype, false, ReturnNewWithProto)
    436 //
    437 //TestConstructFromCall(Object.prototype, true,
    438 //                      Proxy.createFunction(handler, ReturnUndef))
    439 //TestConstructFromCall(Object.prototype, true,
    440 //                      Proxy.createFunction(handler, ReturnThis))
    441 //TestConstructFromCall(Object.prototype, false,
    442 //                      Proxy.createFunction(handler, ReturnNew))
    443 //TestConstructFromCall(prototype, false,
    444 //                      Proxy.createFunction(handler, ReturnNewWithProto))
    445 //
    446 //TestConstructFromCall(prototype, true,
    447 //                      Proxy.createFunction(handlerWithPrototype, ReturnUndef))
    448 //TestConstructFromCall(prototype, true,
    449 //                      Proxy.createFunction(handlerWithPrototype, ReturnThis))
    450 //TestConstructFromCall(Object.prototype, false,
    451 //                      Proxy.createFunction(handlerWithPrototype, ReturnNew))
    452 //TestConstructFromCall(prototype, false,
    453 //                      Proxy.createFunction(handlerWithPrototype,
    454 //                                           ReturnNewWithProto))
    455 //
    456 //TestConstructFromCall(prototype, true,
    457 //                      CreateFrozen(handlerWithPrototype, ReturnUndef))
    458 //TestConstructFromCall(prototype, true,
    459 //                      CreateFrozen(handlerWithPrototype, ReturnThis))
    460 //TestConstructFromCall(Object.prototype, false,
    461 //                      CreateFrozen(handlerWithPrototype, ReturnNew))
    462 //TestConstructFromCall(prototype, false,
    463 //                      CreateFrozen(handlerWithPrototype, ReturnNewWithProto))
    464 //
    465 //
    466 //
    467 //// Throwing from the construct trap.
    468 //
    469 //function TestConstructThrow(trap) {
    470 //  TestConstructThrow2(Proxy.createFunction({ fix: function() {return {};} },
    471 //                                           trap))
    472 //  TestConstructThrow2(Proxy.createFunction({ fix: function() {return {};} },
    473 //                                           function() {},
    474 //                                           trap))
    475 //}
    476 //
    477 //function TestConstructThrow2(f) {
    478 //  assertThrows(function(){ new f(11) }, "myexn")
    479 //  Object.freeze(f)
    480 //  assertThrows(function(){ new f(11) }, "myexn")
    481 //}
    482 //
    483 //TestConstructThrow(function() { throw "myexn" })
    484 //TestConstructThrow(Proxy.createFunction({}, function() { throw "myexn" }))
    485 //TestConstructThrow(CreateFrozen({}, function() { throw "myexn" }))
    486 //
    487 //
    488 //
    489 //// Using function proxies as getters and setters.
    490 //
    491 //var value
    492 //var receiver
    493 //
    494 //function TestAccessorCall(getterCallTrap, setterCallTrap) {
    495 //  var handler = { fix: function() { return {} } }
    496 //  var pgetter = Proxy.createFunction(handler, getterCallTrap)
    497 //  var psetter = Proxy.createFunction(handler, setterCallTrap)
    498 //
    499 //  var o = {}
    500 //  var oo = Object.create(o)
    501 //  Object.defineProperty(o, "a", {get: pgetter, set: psetter})
    502 //  Object.defineProperty(o, "b", {get: pgetter})
    503 //  Object.defineProperty(o, "c", {set: psetter})
    504 //  Object.defineProperty(o, "3", {get: pgetter, set: psetter})
    505 //  Object.defineProperty(oo, "a", {value: 43})
    506 //
    507 //  receiver = ""
    508 //  assertEquals(42, o.a)
    509 //  assertSame(o, receiver)
    510 //  receiver = ""
    511 //  assertEquals(42, o.b)
    512 //  assertSame(o, receiver)
    513 //  receiver = ""
    514 //  assertEquals(undefined, o.c)
    515 //  assertEquals("", receiver)
    516 //  receiver = ""
    517 //  assertEquals(42, o["a"])
    518 //  assertSame(o, receiver)
    519 //  receiver = ""
    520 //  assertEquals(42, o[3])
    521 //  assertSame(o, receiver)
    522 //
    523 //  receiver = ""
    524 //  assertEquals(43, oo.a)
    525 //  assertEquals("", receiver)
    526 //  receiver = ""
    527 //  assertEquals(42, oo.b)
    528 //  assertSame(oo, receiver)
    529 //  receiver = ""
    530 //  assertEquals(undefined, oo.c)
    531 //  assertEquals("", receiver)
    532 //  receiver = ""
    533 //  assertEquals(43, oo["a"])
    534 //  assertEquals("", receiver)
    535 //  receiver = ""
    536 //  assertEquals(42, oo[3])
    537 //  assertSame(oo, receiver)
    538 //
    539 //  receiver = ""
    540 //  assertEquals(50, o.a = 50)
    541 //  assertSame(o, receiver)
    542 //  assertEquals(50, value)
    543 //  receiver = ""
    544 //  assertEquals(51, o.b = 51)
    545 //  assertEquals("", receiver)
    546 //  assertEquals(50, value)  // no setter
    547 //  assertThrows(function() { "use strict"; o.b = 51 }, TypeError)
    548 //  receiver = ""
    549 //  assertEquals(52, o.c = 52)
    550 //  assertSame(o, receiver)
    551 //  assertEquals(52, value)
    552 //  receiver = ""
    553 //  assertEquals(53, o["a"] = 53)
    554 //  assertSame(o, receiver)
    555 //  assertEquals(53, value)
    556 //  receiver = ""
    557 //  assertEquals(54, o[3] = 54)
    558 //  assertSame(o, receiver)
    559 //  assertEquals(54, value)
    560 //
    561 //  value = 0
    562 //  receiver = ""
    563 //  assertEquals(60, oo.a = 60)
    564 //  assertEquals("", receiver)
    565 //  assertEquals(0, value)  // oo has own 'a'
    566 //  assertEquals(61, oo.b = 61)
    567 //  assertSame("", receiver)
    568 //  assertEquals(0, value)  // no setter
    569 //  assertThrows(function() { "use strict"; oo.b = 61 }, TypeError)
    570 //  receiver = ""
    571 //  assertEquals(62, oo.c = 62)
    572 //  assertSame(oo, receiver)
    573 //  assertEquals(62, value)
    574 //  receiver = ""
    575 //  assertEquals(63, oo["c"] = 63)
    576 //  assertSame(oo, receiver)
    577 //  assertEquals(63, value)
    578 //  receiver = ""
    579 //  assertEquals(64, oo[3] = 64)
    580 //  assertSame(oo, receiver)
    581 //  assertEquals(64, value)
    582 //}
    583 //
    584 //TestAccessorCall(
    585 //  function() { receiver = this; return 42 },
    586 //  function(x) { receiver = this; value = x }
    587 //)
    588 //
    589 //TestAccessorCall(
    590 //  function() { "use strict"; receiver = this; return 42 },
    591 //  function(x) { "use strict"; receiver = this; value = x }
    592 //)
    593 //
    594 //TestAccessorCall(
    595 //  Proxy.createFunction({}, function() { receiver = this; return 42 }),
    596 //  Proxy.createFunction({}, function(x) { receiver = this; value = x })
    597 //)
    598 //
    599 //TestAccessorCall(
    600 //  CreateFrozen({}, function() { receiver = this; return 42 }),
    601 //  CreateFrozen({}, function(x) { receiver = this; value = x })
    602 //)
    603 //
    604 //
    605 //
    606 //// Passing a proxy function to higher-order library functions.
    607 //
    608 //function TestHigherOrder(f) {
    609 //  assertEquals(6, [6, 2].map(f)[0])
    610 //  assertEquals(4, [5, 2].reduce(f, 4))
    611 //  assertTrue([1, 2].some(f))
    612 //  assertEquals("a.b.c", "a.b.c".replace(".", f))
    613 //}
    614 //
    615 //TestHigherOrder(function(x) { return x })
    616 //TestHigherOrder(function(x) { "use strict"; return x })
    617 //TestHigherOrder(Proxy.createFunction({}, function(x) { return x }))
    618 //TestHigherOrder(CreateFrozen({}, function(x) { return x }))
    619 //
    620 //
    621 //
    622 //// TODO(rossberg): Ultimately, I want to have the following test function
    623 //// run through, but it currently fails on so many cases (some not even
    624 //// involving proxies), that I leave that for later...
    625 ///*
    626 //function TestCalls() {
    627 //  var handler = {
    628 //    get: function(r, k) {
    629 //      return k == "length" ? 2 : Function.prototype[k]
    630 //    }
    631 //  }
    632 //  var bind = Function.prototype.bind
    633 //  var o = {}
    634 //
    635 //  var traps = [
    636 //    function(x, y) {
    637 //      return {receiver: this, result: x + y, strict: false}
    638 //    },
    639 //    function(x, y) { "use strict";
    640 //      return {receiver: this, result: x + y, strict: true}
    641 //    },
    642 //    function() {
    643 //      var x = arguments[0], y = arguments[1]
    644 //      return {receiver: this, result: x + y, strict: false}
    645 //    },
    646 //    Proxy.createFunction(handler, function(x, y) {
    647 //      return {receiver: this, result: x + y, strict: false}
    648 //    }),
    649 //    Proxy.createFunction(handler, function() {
    650 //      var x = arguments[0], y = arguments[1]
    651 //      return {receiver: this, result: x + y, strict: false}
    652 //    }),
    653 //    Proxy.createFunction(handler, function(x, y) { "use strict"
    654 //      return {receiver: this, result: x + y, strict: true}
    655 //    }),
    656 //    CreateFrozen(handler, function(x, y) {
    657 //      return {receiver: this, result: x + y, strict: false}
    658 //    }),
    659 //    CreateFrozen(handler, function(x, y) { "use strict"
    660 //      return {receiver: this, result: x + y, strict: true}
    661 //    }),
    662 //  ]
    663 //  var creates = [
    664 //    function(trap) { return trap },
    665 //    function(trap) { return CreateFrozen({}, callTrap) },
    666 //    function(trap) { return Proxy.createFunction(handler, callTrap) },
    667 //    function(trap) {
    668 //      return Proxy.createFunction(handler, CreateFrozen({}, callTrap))
    669 //    },
    670 //    function(trap) {
    671 //      return Proxy.createFunction(handler, Proxy.createFunction(handler, callTrap))
    672 //    },
    673 //  ]
    674 //  var binds = [
    675 //    function(f, o, x, y) { return f },
    676 //    function(f, o, x, y) { return bind.call(f, o) },
    677 //    function(f, o, x, y) { return bind.call(f, o, x) },
    678 //    function(f, o, x, y) { return bind.call(f, o, x, y) },
    679 //    function(f, o, x, y) { return bind.call(f, o, x, y, 5) },
    680 //    function(f, o, x, y) { return bind.call(bind.call(f, o), {}, x, y) },
    681 //    function(f, o, x, y) { return bind.call(bind.call(f, o, x), {}, y) },
    682 //    function(f, o, x, y) { return bind.call(bind.call(f, o, x, y), {}, 5) },
    683 //  ]
    684 //  var calls = [
    685 //    function(f, x, y) { return f(x, y) },
    686 //    function(f, x, y) { var g = f; return g(x, y) },
    687 //    function(f, x, y) { with ({}) return f(x, y) },
    688 //    function(f, x, y) { var g = f; with ({}) return g(x, y) },
    689 //    function(f, x, y, o) { with (o) return f(x, y) },
    690 //    function(f, x, y, o) { return f.call(o, x, y) },
    691 //    function(f, x, y, o) { return f.apply(o, [x, y]) },
    692 //    function(f, x, y, o) { return Function.prototype.call.call(f, o, x, y) },
    693 //    function(f, x, y, o) { return Function.prototype.apply.call(f, o, [x, y]) },
    694 //    function(f, x, y, o) { return %_Call(f, o, x, y) },
    695 //    function(f, x, y, o) { return %Call(f, o, x, y) },
    696 //    function(f, x, y, o) { return %Apply(f, o, [null, x, y, null], 1, 2) },
    697 //    function(f, x, y, o) { return %Apply(f, o, arguments, 2, 2) },
    698 //    function(f, x, y, o) { if (typeof o == "object") return o.f(x, y) },
    699 //    function(f, x, y, o) { if (typeof o == "object") return o["f"](x, y) },
    700 //    function(f, x, y, o) { if (typeof o == "object") return (1, o).f(x, y) },
    701 //    function(f, x, y, o) { if (typeof o == "object") return (1, o)["f"](x, y) },
    702 //  ]
    703 //  var receivers = [o, global_object, undefined, null, 2, "bla", true]
    704 //  var expectedSloppies = [o, global_object, global_object, global_object]
    705 //
    706 //  for (var t = 0; t < traps.length; ++t) {
    707 //    for (var i = 0; i < creates.length; ++i) {
    708 //      for (var j = 0; j < binds.length; ++j) {
    709 //        for (var k = 0; k < calls.length; ++k) {
    710 //          for (var m = 0; m < receivers.length; ++m) {
    711 //            for (var n = 0; n < receivers.length; ++n) {
    712 //              var bound = receivers[m]
    713 //              var receiver = receivers[n]
    714 //              var func = binds[j](creates[i](traps[t]), bound, 31, 11)
    715 //              var expected = j > 0 ? bound : receiver
    716 //              var expectedSloppy = expectedSloppies[j > 0 ? m : n]
    717 //              o.f = func
    718 //              global_object.f = func
    719 //              var x = calls[k](func, 11, 31, receiver)
    720 //              if (x !== undefined) {
    721 //                assertEquals(42, x.result)
    722 //                if (calls[k].length < 4)
    723 //                  assertSame(x.strict ? undefined : global_object, x.receiver)
    724 //                else if (x.strict)
    725 //                  assertSame(expected, x.receiver)
    726 //                else if (expectedSloppy === undefined)
    727 //                  assertSame(expected, x.receiver.valueOf())
    728 //                else
    729 //                  assertSame(expectedSloppy, x.receiver)
    730 //              }
    731 //            }
    732 //          }
    733 //        }
    734 //      }
    735 //    }
    736 //  }
    737 //}
    738 //
    739 //TestCalls()
    740 //*/
    741 //
    742 //var realms = [Realm.create(), Realm.create()];
    743 //Realm.shared = {};
    744 //
    745 //Realm.eval(realms[0], "function f() { return this; };");
    746 //Realm.eval(realms[0], "Realm.shared.f = f;");
    747 //Realm.eval(realms[0], "Realm.shared.fg = this;");
    748 //Realm.eval(realms[1], "function g() { return this; };");
    749 //Realm.eval(realms[1], "Realm.shared.g = g;");
    750 //Realm.eval(realms[1], "Realm.shared.gg = this;");
    751 //
    752 //var fp = Proxy.createFunction({}, Realm.shared.f);
    753 //var gp = Proxy.createFunction({}, Realm.shared.g);
    754 //
    755 //for (var i = 0; i < 10; i++) {
    756 //  assertEquals(Realm.shared.fg, fp());
    757 //  assertEquals(Realm.shared.gg, gp());
    758 //
    759 //  with (this) {
    760 //    assertEquals(this, fp());
    761 //    assertEquals(this, gp());
    762 //  }
    763 //
    764 //  with ({}) {
    765 //    assertEquals(Realm.shared.fg, fp());
    766 //    assertEquals(Realm.shared.gg, gp());
    767 //  }
    768 //}
    769