diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2015-01-07 18:38:38 +0100 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2015-01-07 22:11:18 +0100 |
commit | dad73f645cde6920e79db956e7ef82ed640d7615 (patch) | |
tree | 7ba3f3fc7e0722c5f130065461b7c56f571af383 /deps/v8/test/mjsunit/es6 | |
parent | 53ba494537259b18b346dc6150d6a100c557e08f (diff) | |
download | node-new-dad73f645cde6920e79db956e7ef82ed640d7615.tar.gz |
deps: upgrade v8 to 3.31.74.1
PR-URL: https://github.com/iojs/io.js/pull/243
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'deps/v8/test/mjsunit/es6')
-rw-r--r-- | deps/v8/test/mjsunit/es6/collections.js | 26 | ||||
-rw-r--r-- | deps/v8/test/mjsunit/es6/debug-stepin-microtasks.js | 101 | ||||
-rw-r--r-- | deps/v8/test/mjsunit/es6/debug-stepnext-for.js | 116 | ||||
-rw-r--r-- | deps/v8/test/mjsunit/es6/generators-debug-scopes.js | 13 | ||||
-rw-r--r-- | deps/v8/test/mjsunit/es6/generators-iteration.js | 5 | ||||
-rw-r--r-- | deps/v8/test/mjsunit/es6/generators-mirror.js | 76 | ||||
-rw-r--r-- | deps/v8/test/mjsunit/es6/generators-objects.js | 2 | ||||
-rw-r--r-- | deps/v8/test/mjsunit/es6/generators-states.js | 67 | ||||
-rw-r--r-- | deps/v8/test/mjsunit/es6/math-log2-log10.js | 60 | ||||
-rw-r--r-- | deps/v8/test/mjsunit/es6/mirror-collections.js | 11 | ||||
-rw-r--r-- | deps/v8/test/mjsunit/es6/mirror-iterators.js | 47 | ||||
-rw-r--r-- | deps/v8/test/mjsunit/es6/unscopables.js | 64 |
12 files changed, 527 insertions, 61 deletions
diff --git a/deps/v8/test/mjsunit/es6/collections.js b/deps/v8/test/mjsunit/es6/collections.js index 60ce46b2e5..92cd087839 100644 --- a/deps/v8/test/mjsunit/es6/collections.js +++ b/deps/v8/test/mjsunit/es6/collections.js @@ -266,7 +266,6 @@ assertTrue(WeakMap.prototype.set instanceof Function) assertTrue(WeakMap.prototype.get instanceof Function) assertTrue(WeakMap.prototype.has instanceof Function) assertTrue(WeakMap.prototype.delete instanceof Function) -assertTrue(WeakMap.prototype.clear instanceof Function) // Test some common JavaScript idioms for WeakSets @@ -275,7 +274,6 @@ assertTrue(s instanceof WeakSet); assertTrue(WeakSet.prototype.add instanceof Function) assertTrue(WeakSet.prototype.has instanceof Function) assertTrue(WeakSet.prototype.delete instanceof Function) -assertTrue(WeakSet.prototype.clear instanceof Function) // Test class of instance and prototype. @@ -471,30 +469,6 @@ for (var i = 9; i >= 0; i--) { })(); -// Test WeakMap clear -(function() { - var k = new Object(); - var w = new WeakMap(); - w.set(k, 23); - assertTrue(w.has(k)); - assertEquals(23, w.get(k)); - w.clear(); - assertFalse(w.has(k)); - assertEquals(undefined, w.get(k)); -})(); - - -// Test WeakSet clear -(function() { - var k = new Object(); - var w = new WeakSet(); - w.add(k); - assertTrue(w.has(k)); - w.clear(); - assertFalse(w.has(k)); -})(); - - (function TestMinusZeroSet() { var s = new Set(); s.add(-0); diff --git a/deps/v8/test/mjsunit/es6/debug-stepin-microtasks.js b/deps/v8/test/mjsunit/es6/debug-stepin-microtasks.js new file mode 100644 index 0000000000..8dbdb3457a --- /dev/null +++ b/deps/v8/test/mjsunit/es6/debug-stepin-microtasks.js @@ -0,0 +1,101 @@ +// Copyright 2014 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax --expose-debug-as debug + +Debug = debug.Debug +var exception = null; +var break_count = 0; +var expected_breaks = -1; + +function listener(event, exec_state, event_data, data) { + try { + if (event == Debug.DebugEvent.Break) { + assertTrue(exec_state.frameCount() != 0, "FAIL: Empty stack trace"); + if (!break_count) { + // Count number of expected breakpoints in this source file. + var source_text = exec_state.frame(0).func().script().source(); + expected_breaks = source_text.match(/\/\/\s*Break\s+\d+\./g).length; + print("Expected breaks: " + expected_breaks); + } + var source = exec_state.frame(0).sourceLineText(); + print("paused at: " + source); + assertTrue(source.indexOf("// Break " + break_count + ".") > 0, + "Unexpected pause at: " + source + "\n" + + "Expected: // Break " + break_count + "."); + if (source.indexOf("StepOver.") !== -1) { + exec_state.prepareStep(Debug.StepAction.StepNext, 1); + } else { + exec_state.prepareStep(Debug.StepAction.StepIn, 1); + } + ++break_count; + } + } catch (e) { + exception = e; + print(e, e.stack); + } +}; + +Debug.setListener(listener); + +Promise.resolve(42) + .then(promise1) + .then(Object) // Should skip stepping into native. + .then(Boolean) // Should skip stepping into native. + .then(promise2) + .catch(promise3) + .catch(function(e) { + %AbortJS("FAIL: uncaught exception " + e); + }); + +function promise1() { + debugger; // Break 0. + return exception || 1; // Break 1. +} // Break 2. + +function promise2() { + throw new Error; // Break 3. +} + +function promise3() { + installObservers(); // Break 4. StepOver. + return break_count; // Break 5. +} // Break 6. + +function installObservers() { + var dummy = {}; + Object.observe(dummy, observer1); + Object.observe(dummy, Object); // Should skip stepping into native. + Object.observe(dummy, Boolean); // Should skip stepping into native. + Object.observe(dummy, observer2); + dummy.foo = 1; +} + +function observer1() { + return exception || 3; // Break 7. +} // Break 8. + +function observer2() { + Promise.resolve().then(promise4); // Break 9. StepOver. + return break_count + 1; // Break 10. +} // Break 11. + +function promise4() { + finalize(); // Break 12. StepOver. + return 0; // Break 13. +} // Break 14. StepOver. + +function finalize() { + var dummy = {}; + Object.observe(dummy, function() { + if (expected_breaks !== break_count) { + %AbortJS("FAIL: expected <" + expected_breaks + "> breaks instead of <" + + break_count + ">"); + } + if (exception !== null) { + %AbortJS("FAIL: exception: " + exception); + } + }); + dummy.foo = 1; +} diff --git a/deps/v8/test/mjsunit/es6/debug-stepnext-for.js b/deps/v8/test/mjsunit/es6/debug-stepnext-for.js new file mode 100644 index 0000000000..98af911ae3 --- /dev/null +++ b/deps/v8/test/mjsunit/es6/debug-stepnext-for.js @@ -0,0 +1,116 @@ +// Copyright 2014 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --expose-debug-as debug --harmony + +Debug = debug.Debug; +var break_count = 0 +var exception = null; +var log = [] + +var s = 0; +var a = [1, 2, 3]; +var i = 0; + +function f() { + "use strict"; + debugger; // Break a + var j; // Break b + + for (var i in null) { // Break c + s += a[i]; + } + + for (j in null) { // Break d + s += a[j]; + } + + for (var i in a) { // Break e + s += a[i]; // Break E + } + + for (j in a) { // Break f + s += a[j]; // Break F + } + + for (let i in a) { // Break g + s += a[i]; // Break G + } + + for (var i of a) { // Break h + s += i; // Break H + } + + for (j of a) { // Break i + s += j; // Break I + } + + for (let i of a) { // Break j + s += i; // Break J + } + + for (var i = 0; i < 3; i++) { // Break k + s += a[i]; // Break K + } + + for (j = 0; j < 3; j++) { // Break l + s += a[j]; // Break L + } + + // TODO(yangguo): add test case for for-let. +} // Break y + +function listener(event, exec_state, event_data, data) { + if (event != Debug.DebugEvent.Break) return; + try { + var line = exec_state.frame(0).sourceLineText(); + var col = exec_state.frame(0).sourceColumn(); + print(line); + var match = line.match(/\/\/ Break (\w)$/); + assertEquals(2, match.length); + log.push(match[1] + col); + exec_state.prepareStep(Debug.StepAction.StepNext, 1); + break_count++; + } catch (e) { + exception = e; + } +} + +Debug.setListener(listener); +f(); +Debug.setListener(null); // Break z + +print(JSON.stringify(log)); +// The let declaration differs from var in that the loop variable +// is declared in every iteration. +var expected = [ + // Entry + "a2","b2", + // Empty for-in-var: var decl, get enumerable + "c7","c16", + // Empty for-in: get enumerable + "d12", + // For-in-var: var decl, get enumerable, assign, body, assign, body, ... + "e7","e16","e11","E4","e11","E4","e11","E4","e11", + // For-in: get enumerable, assign, body, assign, body, ... + "f12","f7","F4","f7","F4","f7","F4","f7", + // For-in-let: get enumerable, next, new let, body, next, new let, ... + "g16","g11","g7","G4","g11","g7","G4","g11","g7","G4","g11", + // For-of-var: var decl, next(), body, next(), body, ... + "h7","h16","H4","h16","H4","h16","H4","h16", + // For-of: next(), body, next(), body, ... + "i12","I4","i12","I4","i12","I4","i12", + // For-of-let: next(), new let, body, next(), new let, ... + "j16","j7","J4","j16","j7","J4","j16","j7","J4","j16", + // For-var: var decl, condition, body, next, condition, body, ... + "k7","k20","K4","k23","k20","K4","k23","k20","K4","k23","k20", + // For: init, condition, body, next, condition, body, ... + "l11","l16","L4","l19","l16","L4","l19","l16","L4","l19","l16", + // Exit. + "y0","z0", +] + +assertArrayEquals(expected, log); +assertEquals(48, s); +assertNull(exception); diff --git a/deps/v8/test/mjsunit/es6/generators-debug-scopes.js b/deps/v8/test/mjsunit/es6/generators-debug-scopes.js index d55e5612de..126572d16f 100644 --- a/deps/v8/test/mjsunit/es6/generators-debug-scopes.js +++ b/deps/v8/test/mjsunit/es6/generators-debug-scopes.js @@ -97,6 +97,7 @@ function CheckScopeChain(scopes, exec_state) { assertEquals(i, response.body.scopes[i].index); assertEquals(scopes[i], response.body.scopes[i].type); if (scopes[i] == debug.ScopeType.Local || + scopes[i] == debug.ScopeType.Script || scopes[i] == debug.ScopeType.Closure) { assertTrue(response.body.scopes[i].object.ref < 0); } else { @@ -159,6 +160,7 @@ function CheckScopeContent(content, number, exec_state) { assertEquals(scope.scopeType(), response.body.type); assertEquals(number, response.body.index); if (scope.scopeType() == debug.ScopeType.Local || + scope.scopeType() == debug.ScopeType.Script || scope.scopeType() == debug.ScopeType.Closure) { assertTrue(response.body.object.ref < 0); } else { @@ -178,6 +180,7 @@ RunTest("Local 1", [], function (exec_state) { CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({}, 0, exec_state); }); @@ -188,6 +191,7 @@ RunTest("Local 2", [1], function (exec_state) { CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({a:1}, 0, exec_state); }); @@ -198,6 +202,7 @@ RunTest("Local 3", [1], function (exec_state) { CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({a:1,x:3}, 0, exec_state); }); @@ -208,6 +213,7 @@ RunTest("Local 4", [1, 2], function (exec_state) { CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({a:1,b:2,x:3,y:4}, 0, exec_state); }); @@ -218,6 +224,7 @@ RunTest("Local 5", [], function (exec_state) { CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({}, 0, exec_state); }); @@ -228,6 +235,7 @@ RunTest("Local 6", [], function (exec_state) { CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({i:5}, 0, exec_state); }); @@ -242,6 +250,7 @@ RunTest("Local 7", [1, 2], function (exec_state) { CheckScopeChain([debug.ScopeType.Local, + debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6}, 0, exec_state); }); @@ -254,6 +263,7 @@ RunTest("With", CheckScopeChain([debug.ScopeType.With, debug.ScopeType.With, debug.ScopeType.Local, + debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({}, 0, exec_state); CheckScopeContent({}, 1, exec_state); @@ -267,6 +277,7 @@ RunTest("Closure 1", function (exec_state) { CheckScopeChain([debug.ScopeType.Local, debug.ScopeType.Closure, + debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({a:1}, 1, exec_state); }, @@ -305,6 +316,7 @@ RunTest("The full monty", debug.ScopeType.With, debug.ScopeType.Closure, debug.ScopeType.Closure, + debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({b:16}, 0, exec_state); CheckScopeContent({a:15}, 1, exec_state); @@ -321,6 +333,7 @@ RunTest("Catch block 1", function (exec_state) { CheckScopeChain([debug.ScopeType.Catch, debug.ScopeType.Local, + debug.ScopeType.Script, debug.ScopeType.Global], exec_state); CheckScopeContent({e:'Exception'}, 0, exec_state); }); diff --git a/deps/v8/test/mjsunit/es6/generators-iteration.js b/deps/v8/test/mjsunit/es6/generators-iteration.js index b6fcdaa487..faeb68380f 100644 --- a/deps/v8/test/mjsunit/es6/generators-iteration.js +++ b/deps/v8/test/mjsunit/es6/generators-iteration.js @@ -41,10 +41,7 @@ function assertIteratorIsClosed(iter) { } function assertThrownIteratorIsClosed(iter) { - // TODO(yusukesuzuki): Since status of a thrown generator is "executing", - // following tests are failed. - // https://code.google.com/p/v8/issues/detail?id=3096 - // assertIteratorIsClosed(iter); + assertIteratorIsClosed(iter); } function TestGeneratorResultPrototype() { diff --git a/deps/v8/test/mjsunit/es6/generators-mirror.js b/deps/v8/test/mjsunit/es6/generators-mirror.js index 6925285882..bf21f4dff5 100644 --- a/deps/v8/test/mjsunit/es6/generators-mirror.js +++ b/deps/v8/test/mjsunit/es6/generators-mirror.js @@ -24,7 +24,7 @@ MirrorRefCache.prototype.lookup = function(handle) { return this.refs_[handle]; } -function TestGeneratorMirror(g, test) { +function TestGeneratorMirror(g, status, line, column, receiver) { // Create mirror and JSON representation. var mirror = debug.MakeMirror(g); var serializer = debug.MakeMirrorSerializer(); @@ -44,41 +44,69 @@ function TestGeneratorMirror(g, test) { assertFalse(mirror.isPrimitive()); assertEquals('Generator', mirror.className()); - assertTrue(mirror.receiver().isUndefined()); + assertEquals(receiver, mirror.receiver().value()); assertEquals(generator, mirror.func().value()); - test(mirror); -} + assertEquals(status, mirror.status()); + + // Note that line numbers are 0-based, not 1-based. + var loc = mirror.sourceLocation(); + if (status === 'suspended') { + assertTrue(!!loc); + assertEquals(line, loc.line); + assertEquals(column, loc.column); + } else { + assertEquals(undefined, loc); + } -var iter = generator(function () { - assertEquals('running', debug.MakeMirror(iter).status()); -}) + TestInternalProperties(mirror, status, receiver); +} -// Note that line numbers are 0-based, not 1-based. -function assertSourceLocation(loc, line, column) { - assertEquals(line, loc.line); - assertEquals(column, loc.column); +function TestInternalProperties(mirror, status, receiver) { + var properties = mirror.internalProperties(); + assertEquals(3, properties.length); + assertEquals("[[GeneratorStatus]]", properties[0].name()); + assertEquals(status, properties[0].value().value()); + assertEquals("[[GeneratorFunction]]", properties[1].name()); + assertEquals(generator, properties[1].value().value()); + assertEquals("[[GeneratorReceiver]]", properties[2].name()); + assertEquals(receiver, properties[2].value().value()); } -TestGeneratorMirror(iter, function (mirror) { - assertEquals('suspended', mirror.status()) - assertSourceLocation(mirror.sourceLocation(), 7, 19); +var iter = generator(function() { + var mirror = debug.MakeMirror(iter); + assertEquals('running', mirror.status()); + assertEquals(undefined, mirror.sourceLocation()); + TestInternalProperties(mirror, 'running'); }); +TestGeneratorMirror(iter, 'suspended', 7, 19); + iter.next(); -TestGeneratorMirror(iter, function (mirror) { - assertEquals('suspended', mirror.status()) - assertSourceLocation(mirror.sourceLocation(), 9, 2); -}); +TestGeneratorMirror(iter, 'suspended', 9, 2); iter.next(); -TestGeneratorMirror(iter, function (mirror) { - assertEquals('suspended', mirror.status()) - assertSourceLocation(mirror.sourceLocation(), 11, 2); -}); +TestGeneratorMirror(iter, 'suspended', 11, 2); iter.next(); -TestGeneratorMirror(iter, function (mirror) { - assertEquals('closed', mirror.status()) +TestGeneratorMirror(iter, 'closed'); + +// Test generator with receiver. +var obj = {foo: 42}; +var iter2 = generator.call(obj, function() { + var mirror = debug.MakeMirror(iter2); + assertEquals('running', mirror.status()); assertEquals(undefined, mirror.sourceLocation()); + TestInternalProperties(mirror, 'running', obj); }); + +TestGeneratorMirror(iter2, 'suspended', 7, 19, obj); + +iter2.next(); +TestGeneratorMirror(iter2, 'suspended', 9, 2, obj); + +iter2.next(); +TestGeneratorMirror(iter2, 'suspended', 11, 2, obj); + +iter2.next(); +TestGeneratorMirror(iter2, 'closed', 0, 0, obj); diff --git a/deps/v8/test/mjsunit/es6/generators-objects.js b/deps/v8/test/mjsunit/es6/generators-objects.js index 25bd0de79d..8039ca8bb1 100644 --- a/deps/v8/test/mjsunit/es6/generators-objects.js +++ b/deps/v8/test/mjsunit/es6/generators-objects.js @@ -67,6 +67,8 @@ function TestGeneratorObject() { assertEquals("Generator", %_ClassOf(iter)); assertEquals("[object Generator]", String(iter)); assertEquals("[object Generator]", Object.prototype.toString.call(iter)); + var gf = iter.__proto__.constructor; + assertEquals("[object GeneratorFunction]", Object.prototype.toString.call(gf)); assertEquals([], Object.getOwnPropertyNames(iter)); assertTrue(iter !== new g()); } diff --git a/deps/v8/test/mjsunit/es6/generators-states.js b/deps/v8/test/mjsunit/es6/generators-states.js new file mode 100644 index 0000000000..0a2173a919 --- /dev/null +++ b/deps/v8/test/mjsunit/es6/generators-states.js @@ -0,0 +1,67 @@ +// Copyright 2014 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Test generator states. + +function Foo() {} +function Bar() {} + +function assertIteratorResult(value, done, result) { + assertEquals({ value: value, done: done}, result); +} + +function assertIteratorIsClosed(iter) { + assertIteratorResult(undefined, true, iter.next()); + // Next and throw on a closed iterator. + assertDoesNotThrow(function() { iter.next(); }); + assertThrows(function() { iter.throw(new Bar); }, Bar); +} + +var iter; +function* nextGenerator() { yield iter.next(); } +function* throwGenerator() { yield iter.throw(new Bar); } + +// Throw on a suspendedStart iterator. +iter = nextGenerator(); +assertThrows(function() { iter.throw(new Foo) }, Foo) +assertThrows(function() { iter.throw(new Foo) }, Foo) +assertIteratorIsClosed(iter); + +// The same. +iter = throwGenerator(); +assertThrows(function() { iter.throw(new Foo) }, Foo) +assertThrows(function() { iter.throw(new Foo) }, Foo) +assertIteratorIsClosed(iter); + +// Next on an executing iterator raises a TypeError. +iter = nextGenerator(); +assertThrows(function() { iter.next() }, TypeError) +assertIteratorIsClosed(iter); + +// Throw on an executing iterator raises a TypeError. +iter = throwGenerator(); +assertThrows(function() { iter.next() }, TypeError) +assertIteratorIsClosed(iter); + +// Next on an executing iterator doesn't change the state of the +// generator. +iter = (function* () { + try { + iter.next(); + yield 1; + } catch (e) { + try { + // This next() should raise the same exception, because the first + // next() left the iter in the executing state. + iter.next(); + yield 2; + } catch (e) { + yield 3; + } + } + yield 4; +})(); +assertIteratorResult(3, false, iter.next()); +assertIteratorResult(4, false, iter.next()); +assertIteratorIsClosed(iter); diff --git a/deps/v8/test/mjsunit/es6/math-log2-log10.js b/deps/v8/test/mjsunit/es6/math-log2-log10.js index 4479894d7d..fa3f46807a 100644 --- a/deps/v8/test/mjsunit/es6/math-log2-log10.js +++ b/deps/v8/test/mjsunit/es6/math-log2-log10.js @@ -25,6 +25,8 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Flags: --allow-natives-syntax + [Math.log10, Math.log2].forEach( function(fun) { assertTrue(isNaN(fun(NaN))); assertTrue(isNaN(fun(fun))); @@ -39,7 +41,59 @@ assertEquals("Infinity", String(fun(Infinity))); }); -for (var i = -300; i < 300; i += 0.7) { - assertEqualsDelta(i, Math.log10(Math.pow(10, i)), 1E-13); - assertEqualsDelta(i, Math.log2(Math.pow(2, i)), 1E-13); +for (var i = -310; i <= 308; i += 0.5) { + assertEquals(i, Math.log10(Math.pow(10, i))); + // Square roots are tested below. + if (i != -0.5 && i != 0.5) assertEquals(i, Math.log2(Math.pow(2, i))); +} + +// Test denormals. +assertEquals(-307.77759430519706, Math.log10(1.5 * Math.pow(2, -1023))); + +// Test Math.log2(2^k) for -1074 <= k <= 1023. +var n = -1074; +// This loop covers n from -1074 to -1043 +for (var lowbits = 1; lowbits <= 0x80000000; lowbits *= 2) { + var x = %_ConstructDouble(0, lowbits); + assertEquals(n, Math.log2(x)); + n++; +} +// This loop covers n from -1042 to -1023 +for (var hibits = 1; hibits <= 0x80000; hibits *= 2) { + var x = %_ConstructDouble(hibits, 0); + assertEquals(n, Math.log2(x)); + n++; +} +// The rest of the normal values of 2^n +var x = 1; +for (var n = -1022; n <= 1023; ++n) { + var x = Math.pow(2, n); + assertEquals(n, Math.log2(x)); +} + +// Test special values. +// Expectation isn't exactly 1/2 because Math.SQRT2 isn't exactly sqrt(2). +assertEquals(0.5000000000000001, Math.log2(Math.SQRT2)); + +// Expectation isn't exactly -1/2 because Math.SQRT1_2 isn't exactly sqrt(1/2). +assertEquals(-0.4999999999999999, Math.log2(Math.SQRT1_2)); + +assertEquals(3.321928094887362, Math.log2(10)); +assertEquals(6.643856189774724, Math.log2(100)); + +// Test relationships +x = 1; +for (var k = 0; k < 1000; ++k) { + var y = Math.abs(Math.log2(x) + Math.log2(1/x)); + assertEqualsDelta(0, y, 1.5e-14); + x *= 1.1; +} + +x = Math.pow(2, -100); +for (var k = 0; k < 1000; ++k) { + var y = Math.log2(x); + var expected = Math.log(x) / Math.LN2; + var err = Math.abs(y - expected) / expected; + assertEqualsDelta(0, err, 1e-15); + x *= 1.1; } diff --git a/deps/v8/test/mjsunit/es6/mirror-collections.js b/deps/v8/test/mjsunit/es6/mirror-collections.js index e10f5c1a98..81a98b8a58 100644 --- a/deps/v8/test/mjsunit/es6/mirror-collections.js +++ b/deps/v8/test/mjsunit/es6/mirror-collections.js @@ -51,6 +51,7 @@ map.set(o2, 22); map.delete(o1); var mapMirror = debug.MakeMirror(map); testMapMirror(mapMirror); + var entries = mapMirror.entries(); assertEquals(1, entries.length); assertSame(o2, entries[0].key); @@ -59,6 +60,7 @@ map.set(o1, 33); map.set(o3, o2); map.delete(o2); map.set(undefined, 44); + entries = mapMirror.entries(); assertEquals(3, entries.length); assertSame(o1, entries[0].key); @@ -68,6 +70,10 @@ assertSame(o2, entries[1].value); assertEquals(undefined, entries[2].key); assertEquals(44, entries[2].value); +assertEquals(3, mapMirror.entries(0).length); +assertEquals(1, mapMirror.entries(1).length); +assertEquals(2, mapMirror.entries(2).length); + // Test the mirror object for Sets var set = new Set(); set.add(o1); @@ -78,6 +84,7 @@ var setMirror = debug.MakeMirror(set); testSetMirror(setMirror); var values = setMirror.values(); assertEquals(2, values.length); +assertEquals(1, setMirror.values(1).length); assertSame(o2, values[0]); assertEquals(undefined, values[1]); @@ -96,6 +103,8 @@ gc(); function testWeakMapEntries(weakMapMirror) { var entries = weakMapMirror.entries(); assertEquals(2, entries.length); + assertEquals(2, weakMapMirror.entries(0).length); + assertEquals(1, weakMapMirror.entries(1).length); var found = 0; for (var i = 0; i < entries.length; i++) { if (Object.is(entries[i].key, o1)) { @@ -129,6 +138,8 @@ gc(); function testWeakSetValues(weakSetMirror) { var values = weakSetMirror.values(); assertEquals(2, values.length); + assertEquals(2, weakSetMirror.values(0).length); + assertEquals(1, weakSetMirror.values(1).length); var found = 0; for (var i = 0; i < values.length; i++) { if (Object.is(values[i], o1)) { diff --git a/deps/v8/test/mjsunit/es6/mirror-iterators.js b/deps/v8/test/mjsunit/es6/mirror-iterators.js index 02fe7ffde0..22ce42493f 100644 --- a/deps/v8/test/mjsunit/es6/mirror-iterators.js +++ b/deps/v8/test/mjsunit/es6/mirror-iterators.js @@ -5,21 +5,40 @@ // Flags: --expose-debug-as debug // Test the mirror object for collection iterators. -function testIteratorMirror(iter, offset, expected) { +function testIteratorMirror(iter, offset, expected, opt_limit) { while (offset-- > 0) iter.next(); var mirror = debug.MakeMirror(iter); assertTrue(mirror.isIterator()); - var preview = mirror.preview(); + var preview = mirror.preview(opt_limit); assertArrayEquals(expected, preview); // Check that iterator has not changed after taking preview. var values = []; - for (var i of iter) values.push(i); + for (var i of iter) { + if (opt_limit && values.length >= opt_limit) break; + values.push(i); + } assertArrayEquals(expected, values); } +function testIteratorInternalProperties(iter, offset, kind, index, has_more) { + while (offset-- > 0) iter.next(); + + var mirror = debug.MakeMirror(iter); + assertTrue(mirror.isIterator()); + + var properties = mirror.internalProperties(); + assertEquals(3, properties.length); + assertEquals("[[IteratorHasMore]]", properties[0].name()); + assertEquals(has_more, properties[0].value().value()); + assertEquals("[[IteratorIndex]]", properties[1].name()); + assertEquals(index, properties[1].value().value()); + assertEquals("[[IteratorKind]]", properties[2].name()); + assertEquals(kind, properties[2].value().value()); +} + var o1 = { foo: 1 }; var o2 = { foo: 2 }; @@ -39,6 +58,16 @@ testIteratorMirror(map.keys(), 2, []); testIteratorMirror(map.values(), 2, []); testIteratorMirror(map.entries(), 2, []); +// Test with maximum limit. +testIteratorMirror(map.keys(), 0, [41], 1); +testIteratorMirror(map.values(), 0, [42], 1); +testIteratorMirror(map.entries(), 0, [[41, 42]], 1); + +testIteratorInternalProperties(map.keys(), 0, "keys", 0, true); +testIteratorInternalProperties(map.values(), 1, "values", 1, true); +testIteratorInternalProperties(map.entries(), 2, "entries", 2, false); +testIteratorInternalProperties(map.keys(), 3, "keys", 2, false); + var set = new Set(); set.add(41); set.add(42); @@ -60,3 +89,15 @@ testIteratorMirror(set.entries(), 3, [[o2, o2]]); testIteratorMirror(set.keys(), 5, []); testIteratorMirror(set.values(), 5, []); testIteratorMirror(set.entries(), 5, []); + +// Test with maximum limit. +testIteratorMirror(set.keys(), 1, [42, o1], 2); +testIteratorMirror(set.values(), 1, [42, o1], 2); +testIteratorMirror(set.entries(), 1, [[42, 42], [o1, o1]], 2); + +testIteratorInternalProperties(set.keys(), 0, "values", 0, true); +testIteratorInternalProperties(set.values(), 1, "values", 1, true); +testIteratorInternalProperties(set.entries(), 2, "entries", 2, true); +testIteratorInternalProperties(set.keys(), 3, "values", 3, true); +testIteratorInternalProperties(set.values(), 4, "values", 4, false); +testIteratorInternalProperties(set.entries(), 5, "entries", 4, false); diff --git a/deps/v8/test/mjsunit/es6/unscopables.js b/deps/v8/test/mjsunit/es6/unscopables.js index 36365d2d82..03612bec53 100644 --- a/deps/v8/test/mjsunit/es6/unscopables.js +++ b/deps/v8/test/mjsunit/es6/unscopables.js @@ -143,6 +143,13 @@ function TestBasics(object) { assertEquals(2, y); assertEquals(3, z); } + + object[Symbol.unscopables] = {x: 0, y: undefined}; + with (object) { + assertEquals(1, x); + assertEquals(5, y); + assertEquals(3, z); + } } runTest(TestBasics); @@ -161,6 +168,13 @@ function TestUnscopableChain(object) { with (object) { assertEquals(1, x); } + + object[Symbol.unscopables] = { + __proto__: {x: undefined} + }; + with (object) { + assertEquals(2, x); + } } runTest(TestUnscopableChain); @@ -222,6 +236,14 @@ function TestOnProto(object, proto) { assertEquals(5, y); assertEquals(3, z); } + + proto[Symbol.unscopables] = {y: true}; + object[Symbol.unscopables] = {x: true, y: undefined}; + with (object) { + assertEquals(1, x); + assertEquals(5, y); + assertEquals(3, z); + } } runTest(TestOnProto); @@ -341,6 +363,20 @@ function TestChangeDuringWithWithPossibleOptimization4(object) { TestChangeDuringWithWithPossibleOptimization4({}); +function TestChangeDuringWithWithPossibleOptimization4(object) { + var x = 1; + object.x = 2; + object[Symbol.unscopables] = {x: true}; + with (object) { + for (var i = 0; i < 1000; i++) { + if (i === 500) object[Symbol.unscopables].x = undefined; + assertEquals(i < 500 ? 1 : 2, x); + } + } +} +TestChangeDuringWithWithPossibleOptimization4({}); + + function TestAccessorReceiver(object, proto) { var x = 'local'; @@ -532,9 +568,11 @@ function TestAccessorOnUnscopables(object) { var x = 1; object.x = 2; + var calls = 0; var unscopables = { get x() { - assertUnreachable(); + calls++; + return calls === 1 ? true : undefined; } }; @@ -542,7 +580,9 @@ function TestAccessorOnUnscopables(object) { assertEquals(2, x); object[Symbol.unscopables] = unscopables; assertEquals(1, x); + assertEquals(2, x); } + assertEquals(2, calls); } runTest(TestAccessorOnUnscopables); @@ -659,3 +699,25 @@ function TestGetUnscopablesGetterThrows() { }, CustomError); } TestGetUnscopablesGetterThrows(); + + +function TestGetUnscopablesGetterThrows2() { + var object = { + get x() { + assertUnreachable(); + } + }; + function CustomError() {} + + object[Symbol.unscopables] = { + get x() { + throw new CustomError(); + } + }; + assertThrows(function() { + with (object) { + x; + } + }, CustomError); +} +TestGetUnscopablesGetterThrows(); |