generators-poisoned-properties.js 1.49 KB
Newer Older
1 2 3 4
// 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.

5 6 7 8 9
(function testRestrictedPropertiesStrict() {
  function* generator() { "use strict"; }
  assertFalse(generator.hasOwnProperty("arguments"));
  assertThrows(function() { return generator.arguments; }, TypeError);
  assertThrows(function() { return generator.arguments = {}; }, TypeError);
10

11 12 13 14
  assertFalse(generator.hasOwnProperty("caller"));
  assertThrows(function() { return generator.caller; }, TypeError);
  assertThrows(function() { return generator.caller = {}; }, TypeError);
})();
15 16


17 18 19 20 21
(function testRestrictedPropertiesSloppy() {
  function* generator() {}
  assertFalse(generator.hasOwnProperty("arguments"));
  assertThrows(function() { return generator.arguments; }, TypeError);
  assertThrows(function() { return generator.arguments = {}; }, TypeError);
22

23 24 25 26
  assertFalse(generator.hasOwnProperty("caller"));
  assertThrows(function() { return generator.caller; }, TypeError);
  assertThrows(function() { return generator.caller = {}; }, TypeError);
})();
27

28 29
function assertIteratorResult(value, done, result) {
  assertEquals({value: value, done: done}, result);
30 31 32
}


33 34 35 36 37
(function testIteratorResultStrict() {
  function* generator() { "use strict"; }
  assertIteratorResult(undefined, true, generator().next());
})();

38

39 40 41 42
(function testIteratorResultSloppy() {
  function* generator() {}
  assertIteratorResult(undefined, true, generator().next());
})();