PageRenderTime 24ms CodeModel.GetById 18ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/js/src/jit-test/tests/basic/testAddAnyInconvertibleObject.js

http://github.com/zpao/v8monkey
JavaScript | 28 lines | 26 code | 2 blank | 0 comment | 7 complexity | 6d46c4ef7f343b12e14a54c39b58e002 MD5 | raw file
 1function testAddAnyInconvertibleObject()
 2{
 3  var count = 0;
 4  function toString() { ++count; if (count == 95) return {}; return "" + count; }
 5  var o = {valueOf: undefined, toString: toString};
 6
 7  var threw = false;
 8  try
 9  {
10    for (var i = 0; i < 100; i++)
11        var q = 5 + o;
12  }
13  catch (e)
14  {
15    threw = true;
16    if (i !== 94)
17      return "expected i === 94, got " + i;
18    if (q !== "594")
19      return "expected q === '594', got " + q + " (type " + typeof q + ")";
20    if (count !== 95)
21      return "expected count === 95, got " + count;
22  }
23  if (!threw)
24    return "expected throw with 5 + o"; // hey, a rhyme!
25
26  return "pass";
27}
28assertEq(testAddAnyInconvertibleObject(), "pass");