summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/language/statements/generators/forbidden-ext/b2/gen-func-decl-forbidden-ext-indirect-access-own-prop-caller-get.js
blob: f54bcc46e9387915bc14110206b05f6690462fa9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// This file was procedurally generated from the following sources:
// - src/function-forms/forbidden-ext-indirect-access-own-prop-caller-get.case
// - src/function-forms/forbidden-extensions/bullet-two/gen-func-decl.template
/*---
description: Forbidden extension, o.caller (generator function declaration)
esid: sec-generator-definitions-runtime-semantics-instantiatefunctionobject
features: [generators]
flags: [generated, noStrict]
info: |
    GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody }


    If an implementation extends any function object with an own property named "caller" the value of
    that property, as observed using [[Get]] or [[GetOwnProperty]], must not be a strict function
    object. If it is an accessor property, the function that is the value of the property's [[Get]]
    attribute must never return a strict function when called.

---*/
var CALLER_OWN_PROPERTY_DOES_NOT_EXIST = Symbol();
function inner() {
  // This property may exist, but is forbidden from having a value that is a strict function object
  return inner.hasOwnProperty("caller")
    ? inner.caller
    : CALLER_OWN_PROPERTY_DOES_NOT_EXIST;
}

var callCount = 0;
function* f() {
  "use strict";
  // This and the following conditional value is set in the test's .case file.
  // For every test that has a "true" value here, there is a
  // corresponding test that has a "false" value here.
  // They are generated from two different case files, which use
  // the same templates.
  let descriptor = Object.getOwnPropertyDescriptor(inner, "caller");
  if (descriptor && descriptor.configurable && true) {
    Object.defineProperty(inner, "caller", {get(){return 1}});
  }
  var result = inner();
  if (descriptor && descriptor.configurable && true) {
    assert.sameValue(result, 1, 'If this test defined an own "caller" property on the inner function, then it should be accessible and should return the value it was set to.');
  }

  // "CALLER_OWN_PROPERTY_DOES_NOT_EXIST" is from
  // forbidden-ext-indirect-access-prop-caller.case
  //
  // If the function object "inner" has an own property
  // named "caller", then its value will be returned.
  //
  // If the function object "inner" DOES NOT have an
  // own property named "caller", then the symbol
  // CALLER_OWN_PROPERTY_DOES_NOT_EXIST will be returned.
  if (result !== CALLER_OWN_PROPERTY_DOES_NOT_EXIST) {
    assert.notSameValue(result, f);
  }

  callCount++;
}

f().next();

assert.sameValue(callCount, 1, 'generator function body evaluated');

reportCompare(0, 0);